gitea: Index | Files

package sync

import ""


Package Files

exclusive_pool.go status_pool.go unique_queue.go

type ExclusivePool Uses

type ExclusivePool struct {
    // contains filtered or unexported fields

ExclusivePool is a pool of non-identical instances that only one instance with same identity is in the pool at a time. In other words, only instances with different identities can be in the pool the same time. If another instance with same identity tries to get into the pool, it hangs until previous instance left the pool.

This pool is particularly useful for performing tasks on same resource on the file system in different goroutines.

func NewExclusivePool Uses

func NewExclusivePool() *ExclusivePool

NewExclusivePool initializes and returns a new ExclusivePool object.

func (*ExclusivePool) CheckIn Uses

func (p *ExclusivePool) CheckIn(identity string)

CheckIn checks in an instance to the pool and hangs while instance with same identity is using the lock.

func (*ExclusivePool) CheckOut Uses

func (p *ExclusivePool) CheckOut(identity string)

CheckOut checks out an instance from the pool and releases the lock to let other instances with same identity to grab the lock.

type StatusTable Uses

type StatusTable struct {
    // contains filtered or unexported fields

StatusTable is a table maintains true/false values.

This table is particularly useful for un/marking and checking values in different goroutines.

func NewStatusTable Uses

func NewStatusTable() *StatusTable

NewStatusTable initializes and returns a new StatusTable object.

func (*StatusTable) IsRunning Uses

func (p *StatusTable) IsRunning(name string) bool

IsRunning checks if value of given name is set to true in the pool.

func (*StatusTable) Start Uses

func (p *StatusTable) Start(name string)

Start sets value of given name to true in the pool.

func (*StatusTable) StartIfNotRunning Uses

func (p *StatusTable) StartIfNotRunning(name string) bool

StartIfNotRunning sets value of given name to true if not already in pool. Returns whether set value was set to true

func (*StatusTable) Stop Uses

func (p *StatusTable) Stop(name string)

Stop sets value of given name to false in the pool.

type UniqueQueue Uses

type UniqueQueue struct {
    // contains filtered or unexported fields

UniqueQueue is a queue which guarantees only one instance of same identity is in the line. Instances with same identity will be discarded if there is already one in the line.

This queue is particularly useful for preventing duplicated task of same purpose.

func NewUniqueQueue Uses

func NewUniqueQueue(queueLength int) *UniqueQueue

NewUniqueQueue initializes and returns a new UniqueQueue object.

func (*UniqueQueue) Add Uses

func (q *UniqueQueue) Add(id interface{})

Add adds new instance to the queue.

func (*UniqueQueue) AddFunc Uses

func (q *UniqueQueue) AddFunc(id interface{}, fn func())

AddFunc adds new instance to the queue with a custom runnable function, the queue is blocked until the function exits.

func (*UniqueQueue) Close Uses

func (q *UniqueQueue) Close()

Close closes this queue

func (*UniqueQueue) Exist Uses

func (q *UniqueQueue) Exist(id interface{}) bool

Exist returns true if there is an instance with given identity exists in the queue.

func (*UniqueQueue) IDs Uses

func (q *UniqueQueue) IDs() []interface{}

IDs returns the current ids in the pool

func (*UniqueQueue) IsClosed Uses

func (q *UniqueQueue) IsClosed() <-chan struct{}

IsClosed returns a channel that is closed when this Queue is closed

func (*UniqueQueue) Queue Uses

func (q *UniqueQueue) Queue() <-chan string

Queue returns channel of queue for retrieving instances.

func (*UniqueQueue) Remove Uses

func (q *UniqueQueue) Remove(id interface{})

Remove removes instance from the queue.

Package sync imports 2 packages (graph) and is imported by 32 packages. Updated 2020-01-27. Refresh now. Tools for package owners.