An open API service indexing awesome lists of open source software.

https://github.com/voidwyrm-2/go-async

A library that implements asynchronous structures over gorountines
https://github.com/voidwyrm-2/go-async

async async-await asynchronous-programming go golang library

Last synced: 6 days ago
JSON representation

A library that implements asynchronous structures over gorountines

Awesome Lists containing this project

README

          

# go-async

go-async implements asynchronous structures, like C#'s `Task`s, over Go's gorountines to allow program structuring more languages such as C# and JavaScript.

## Installation

Run `go get github.com/voidwyrm-2/go-async@latest` to add it to your project.

## Example

```go
package main

import (
"fmt"
"time"

"github.com/voidwyrm-2/go-async"
)

func main() {
p := goasync.NewTask(func() (struct{}, error) {
for i := range 4 {
time.Sleep(time.Second * 2)
fmt.Printf("async thing %d finished\n", i)
}

return struct{}{}, nil
})

p.Start()

fmt.Println("doing things...")
time.Sleep(time.Second)
fmt.Println("doing more things...")
time.Sleep(time.Second)
fmt.Println("doing the last things...")
time.Sleep(time.Second * 3)
fmt.Println("waiting for background processes")

p.Await()

fmt.Println("all done!")
}
```