syncutil

package
v4.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2022 License: Apache-2.0 Imports: 1 Imported by: 10

Documentation

Overview

Copyright 2017 Mailgun Technologies Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster interface {
	WaitChan(string) chan struct{}
	Wait(string)
	Broadcast()
	Done()
}

func NewBroadcaster

func NewBroadcaster() Broadcaster

type FanOut

type FanOut struct {
	// contains filtered or unexported fields
}

FanOut spawns a new go-routine each time `Run()` is called until `size` is reached, subsequent calls to `Run()` will block until previously `Run()` routines have completed. Allowing the user to control how many routines will run simultaneously. `Wait()` then collects any errors from the routines once they have all completed.

func NewFanOut

func NewFanOut(size int) *FanOut

func (*FanOut) Run

func (p *FanOut) Run(callBack func(interface{}) error, data interface{})

Run a new routine with an optional data value

func (*FanOut) Wait

func (p *FanOut) Wait() []error

Wait for all the routines to complete and return any errors

type WaitGroup

type WaitGroup struct {
	// contains filtered or unexported fields
}

func (*WaitGroup) Go

func (wg *WaitGroup) Go(cb func())

Execute a long running routine

func (*WaitGroup) Loop

func (wg *WaitGroup) Loop(callBack func() bool)

Run a goroutine in a loop continuously, if the callBack returns false the loop is broken

func (*WaitGroup) Run

func (wg *WaitGroup) Run(callBack func(interface{}) error, data interface{})

Run a routine and collect errors if any

func (*WaitGroup) Stop

func (wg *WaitGroup) Stop()

Stop closes the done channel passed into `Until()` calls and waits for the `Until()` callBack to return false.

func (*WaitGroup) Until

func (wg *WaitGroup) Until(callBack func(done chan struct{}) bool)

Run a goroutine in a loop continuously, if the callBack returns false the loop is broken. `Until()` differs from `Loop()` in that if the `Stop()` is called on the WaitGroup the `done` channel is closed. Implementations of the callBack function can listen for the close to indicate a stop was requested.

func (*WaitGroup) Wait

func (wg *WaitGroup) Wait() []error

Wait for all the routines to complete and return any errors collected

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL