Skip to content
/ VGo Public

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

License

Notifications You must be signed in to change notification settings

VennDev/VGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VGo

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

Install

go get github.com/VennDev/VGo

Example

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
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages