async

package
v3.2.1-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: GPL-3.0 Imports: 8 Imported by: 7

Documentation

Overview

Package async includes helpers for scheduling runnable, periodic functions and contains useful helpers for converting multi-processor computation.

Copyright 2017 Albert Tedja 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

func Clean

func Clean() []string

Clean cleans old unused locks. Returns removed keys.

func Debounce

func Debounce(ctx context.Context, interval time.Duration, eventsChan <-chan interface{}, handler func(interface{}))

Debounce events fired over a channel by a specified duration, ensuring no events are handled until a certain interval of time has passed.

func RunEvery

func RunEvery(ctx context.Context, period time.Duration, f func())

RunEvery runs the provided command periodically. It runs in a goroutine, and can be cancelled by finishing the supplied context.

Types

type Lock

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

func NewMultilock

func NewMultilock(locks ...string) *Lock

NewMultilock creates a new multilock for the specified keys

func (*Lock) Lock

func (lk *Lock) Lock()

func (*Lock) Unlock

func (lk *Lock) Unlock()

Unlock unlocks this lock. Must be called after Lock. Can only be invoked if there is a previous call to Lock.

func (*Lock) Yield

func (lk *Lock) Yield()

Yield temporarily unlocks, gives up the cpu time to other goroutine, and attempts to lock again.

type WorkerResults

type WorkerResults struct {
	Offset int
	Extent interface{}
}

WorkerResults are the results of a scatter worker.

func Scatter

func Scatter(inputLen int, sFunc func(int, int, *sync.RWMutex) (interface{}, error)) ([]*WorkerResults, error)

Scatter scatters a computation across multiple goroutines. This breaks the task in to a number of chunks and executes those chunks in parallel with the function provided. Results returned are collected and presented a a set of WorkerResults, which can be reassembled by the calling function. Any error that occurs in the workers will be passed back to the calling function.

Directories

Path Synopsis
Package abool provides atomic Boolean type for cleaner code and better performance.
Package abool provides atomic Boolean type for cleaner code and better performance.
Package event contains an event feed implementation for process communication.
Package event contains an event feed implementation for process communication.

Jump to

Keyboard shortcuts

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