Skip to content

yolo-pkgs/async

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async go fork

Uses golang.org/x/sync/errgroup internally. API is not changed.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/barklan/async"
)

type User struct {
	name string
}

func main() {
	promise := async.NewPromise(func() (User, error) {
		time.Sleep(2 * time.Second)
		return User{name: "Test"}, nil
	})

	fmt.Println("do someting else")

	user, err := promise.Await(context.Background())
	if err != nil {
		log.Panic(err)
	}
	fmt.Println(user)
}

About

Experimental promises in go1.18 with generics.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%