Categorygithub.com/Azure/go-asynctask
modulepackage
2.0.1-alpha+incompatible
Repository: https://github.com/azure/go-asynctask.git
Documentation: pkg.go.dev

# README

AsyncTask

Build Go Report Card GoDoc Codecov

Simple mimik of async/await for those come from C# world, so you don't need to dealing with waitGroup/channel in golang.

    // start task
    task := asynctask.Start(ctx, countingTask)
    
    // do something else
    somethingelse()
    
    // get the result
    rawResult, err := task.Wait()
    // or
    task.Cancel()

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

# Functions

ActionToFunc convert a Action to Func (C# term), to satisfy the AsyncFunc interface.
AfterBoth runs the function after both 2 input task finished, and will be fed with result from 2 input task.
AfterBothActionToFunc convert a Action to Func (C# term), to satisfy the AfterBothFunc interface.
ContinueActionToFunc convert a Action to Func (C# term), to satisfy the AsyncFunc interface.
No description provided by the author
NewCompletedTask returns a Completed task, with result=nil, error=nil.
Start run a async function and returns you a handle which you can Wait or Cancel.
WaitAll block current thread til all task finished.
WaitAny block current thread til any of task finished.

# Constants

StateCanceled indicate task got canceled.
StateCompleted indicate task is finished.
StateFailed indicate task failed.
StateRunning indicate task is still running.

# Variables

ErrCanceled is returned if a cancel is triggered.
ErrPanic is returned if panic cought in the task.

# Structs

Task is a handle to the running function.
WaitAllOptions defines options for WaitAll function.
WaitAnyOptions defines options for WaitAny function.

# Interfaces

No description provided by the author

# Type aliases

AfterBothFunc is a function that has 2 input.
AsyncFunc is a function interface this asyncTask accepts.
ContinueFunc is a function that can be connected to previous task with ContinueWith.
State of a task.