Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Welcome to our site

Take a moment to join our board

Sign in to follow this  
Spirited

Tasks in Golang

Recommended Posts

Introduction

Tasks is a library for implementing an async-await design pattern in Golang for recoverable, safe goroutine execution. Allows goroutines to be waited upon, canceled, etc. using channels and wait groups. Statuses are returned for fault tolerance checks. If the child goroutine panics, the task recovers and doesn't stop the main execution of the program.

Examples

Below is a simple example of implementing tasks for a single task and multiple tasks. More examples can be found in tasks_test.go, where 100% of the code is covered by tests.

import "spirited.io/tasks"

// This is an example of a single task
task := tasks.Start(nil, MyFunction)
task.Wait()
import (
    "spirited.io/tasks"
    "sync"
)

// This is an example of a single task
var wg sync.WaitGroup
tasks.Start(&wg, MyFirstFunction)
tasks.Start(&wg, MySecondFunction)
wg.Wait()

Link

https://gitlab.com/spirited/tasks

Share this post


Link to post
Share on other sites
8 hours ago, Smallxmac said:

Was this generally based on tasking or also based on the TPL?

Based on need.

Share this post


Link to post
Share on other sites
On 3/26/2019 at 10:54 PM, Spirited said:

Based on need.

I was more asking about design inspiration, but that just seems subconscious to you from the background you have had. 

Share this post


Link to post
Share on other sites
44 minutes ago, Smallxmac said:

I was more asking about design inspiration, but that just seems subconscious to you from the background you have had. 

Yeah, I mean, I suppose it's a bit inspired by C# Tasks, but the name of the package is "tasks" because it's shorter than "saferoutines" or "routines". All this package does is create a panic-safe wrapper around goroutines and integrate a method of waiting. I want to also add a method for cancelling tasks using the context package, but I haven't gotten around to doing that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.