Skip to content
/ async Public

Collection of go-routine synchronization/concurrency processing utilities.

License

Notifications You must be signed in to change notification settings

cadigun/async

Repository files navigation

Async goroutine sychronization & concurrency tool

How to use:

  1. Job: safely run goroutines, supports graceful shutdown. (Credits: @kai.pei)
Example:

job := MakeJob()

// register in graceful/background listener
gracefulServer.Go(job) or background.Observe(job)

// invoke in any function
job.Go(func(){

	err := SomeFunc(arg1, arg2, ...)
	if err == nil {
		// error handling
	}
})

  1. Threading: handles safe concurrent read & execution of data in multiple goroutine threads, and supports graceful shutdown.
Example:

th, err := MakeThreading(Util{
	Read:         func(offset, block int) (interface{}, error) { return []int{}, nil },
	Execute:      func(data interface{}, block int) error { return nil },
	MakeInterval: func() (idx, limit int, err error) { return 0, 100, nil },
	BlockSize:    10,
	Nodes:        5,
})
if err != nil {
	// error handling
}

// register in graceful/background listener
gracefulServer.Go(th) or background.Observe(th)


// run tasks
th.Go()
  1. Background: handles graceful shutdown of background jobs when server is not running. If http server is not running, graceful cannot be used to shutdown running jobs. Instead, use the background listener.
Example:

// main function
background = NewListener()
defer background.Quit()


// function call
background.Observe(Job1)
background.Observe(Job2)
background.Observe(Cron1)
background.Observe(Cron2)


// notes: if signal termination is invoked at any time, the running jobs/cron will terminate gracefully.

About

Collection of go-routine synchronization/concurrency processing utilities.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages