Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/venndev/vgo
- Owner: VennDev
- License: apache-2.0
- Created: 2024-09-13T05:32:49.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-16T16:37:13.000Z (3 months ago)
- Last Synced: 2024-09-16T20:23:37.201Z (3 months ago)
- Topics: async-await, asynchronous, asynchronous-programming, golang-package, goroutine, goroutines
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 vgoimport (
"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
}
```