runqueue

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

runqueue

Build Status Go Report Card Coverage Godoc Releases LICENSE

Installation
go get -u github.com/jackal-xmpp/runqueue
Usage

The runqueue package allows to enqueue and run functions in serial order ensuring exclusive access.

Example
package main 

import (
    "fmt"
    "log"

    "github.com/jackal-xmpp/runqueue"
)

func main() {
    rq := runqueue.New("rq-1", log.Printf)

    var counter int32
    for i := 0; i < 2500; i++ {
        rq.Run(func() { counter++ })
    }
    fmt.Println(counter)
}

Expected output:

2500
Contributing
  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request
License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RunQueue

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

RunQueue represents a lock-free operation queue.

func New

func New(name string, logPanicFn func(format string, args ...interface{})) *RunQueue

New returns an initialized lock-free operation queue.

func (*RunQueue) Run

func (m *RunQueue) Run(fn func())

Run pushes a new operation function into the queue.

func (*RunQueue) Stop

func (m *RunQueue) Stop(stopCb func())

Stop signals the queue to stop running.

Callback function represented by 'stopCb' its guaranteed to be immediately executed only if no job has been previously scheduled.

Directories

Path Synopsis
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.
Package mpsc provides an efficient implementation of a multi-producer, single-consumer lock-free queue.

Jump to

Keyboard shortcuts

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