Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/danlavine/goasync

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/danlavine/goasync

  • v1.0.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

GoAsync - Flexible processes management library

godoc

Go Async is designed to simplify managing multi-process applications into easily understandable single purpose units of work.

The Task Manager is responsible for running and managing any number of assigned tasks. For the Task Manager to operate, each task must follow 1 of two patterns.

Long Running Task

Is expected to run for the entire process's execution.

  1. Each task added to the Task Manager will initialize serially in the order they were added to the Task Manager a. If an error occurs, stop Initializng any remaning tasks. Also Run Cleanup for any tasks that have already been Initialized
  2. In Parallel Run all Execute(...) functions for any tasks a. All tasks are expected to run and not error. b. If any tasks return an error, the Task Manager will cancel all running tasks and then run the Cleanup for each task.
  3. When the Task Manager's context is canceled, each task process will have their context canceled
  4. Each Task's Cleanup function is called in reverse order they were added to the Task Manager

Task interface:

// A Task is anything that can be managed by the TaskManager and added before the taskmanager
// start running. Any errors will cause the process to exit as all tasks are expected to run without erros
type Task interface {
// Initializate functions are ran serially in the order they were added to the TaskManager.
// These are useful when one Goroutine dependency requires a previous Worker to setup some common
// dendency like a DB connection.
Initialize() error

// Execute is the main Async function to house all the multi-threaded logic handled by GoAsync.
Execute(ctx context.Context) error

// Clenup functions are ran serially in reverse order they were added to the TaskManager.
// This way the 1st Initialze dependency is stopped last
Cleanup() error
}

Execute Task

Can be added to a process that is already running

Exeute Task interface:

// A ExecuteTask can be added to a Task Manager before or after it has already started managin the tasks.
// These tasks are expected to already be properly Initialized and don't require any Cleanup Code.
type ExecuteTask interface {
  // Execute is the main Async function to house all the multi-threaded logic handled by GoAsync.
  Execute(ctx context.Context) error
}

Provided tasks

For a number of common basic tasks provided, see tasks directory

Installation

go get -u github.com/DanLavine/goasync

Examples

For a few simple and basic real world example check out the internal/examples dir

Running tests

To run all tests:

go test --race ./...

If we want to run one specific test we can use:

go test --race -run [NAME OF TEST] ./...

To ignore the test cache:

go test --race -count=1 ./...

FAQs

Package last updated on 18 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc