Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/venndev/vgo

The library helps you have the async-await syntax in Go that runs on goroutines.
https://github.com/venndev/vgo

async-await asynchronous asynchronous-programming golang-package goroutine goroutines

Last synced: about 2 months ago
JSON representation

The library helps you have the async-await syntax in Go that runs on goroutines.

Awesome Lists containing this project

README

        

# VGo
The library helps you have the async-await syntax in Go that runs on goroutines.

# Install
`go get github.com/VennDev/VGo`

# Example
```go
package vgo

import (
"fmt"
"strconv"
"testing"
)

func doAsync() *Async {
return &Async{
Callback: func() interface{} {
return 30
},
}
}

func TestAsync(t *testing.T) {
async := doAsync()
result := Await(async)
fmt.Println("Result async:", strconv.Itoa(result.(int))) // Output: Result async: 30
}

func TestDeferred(t *testing.T) {
deferred := &Deferred{
Callback: func() interface{} {
return 50
},
}
result := deferred.Await()
fmt.Println("Result deferred:", strconv.Itoa(result.(int))) // Output: Result deferred: 50
}

func TestDeferredAll(t *testing.T) {
deferred := &Deferred{}
result := deferred.All(
func() interface{} {
return 10
},
func() interface{} {
return 20
},
func() interface{} {
return 30
},
).Await()
fmt.Println("Result deferred all:", result) // Output: Result deferred all: [10 20 30]
}

func TestDeferredAny(t *testing.T) {
deferred := &Deferred{}
result := deferred.Any(
func() interface{} {
return 10
},
func() interface{} {
return 20
},
func() interface{} {
return 30
},
).Await()
fmt.Println("Result deferred any:", result) // Output: Result deferred any: 10
}
```