Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

code.nkcmr.net/async

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code.nkcmr.net/async

  • v0.0.2
  • Go
  • Socket score

Version published
Created
Source

async go

a prototype of "promises" in go1.18.

note: this is just an experiment used to test alternate patterns for dealing with asynchronous code in go. i would not recommend adopting this pattern blindly (especially in production environments) until there is a broader consensus in the go community about this. it might turn out that through some hands-on experience that go's native channels/goroutines are a good enough abstraction and there are no gains to be made from building on top of them.

install

should be just a regular package:

go get -u -v code.nkcmr.net/async@latest

usage

promises abstract away a lot of details about how asynchronous work is handled. so if you need for something to be async, simply us a promise:

import (
    "context"
    "code.nkcmr.net/async"
)

type MyData struct {/* ... */}

func AsyncFetchData(ctx context.Context, dataID int64) async.Promise[MyData] {
    return async.NewPromise(func() (MyData, error) {
        /* ... */
        return myDataFromRemoteServer, nil
    })
}

func DealWithData(ctx context.Context) {
    myDataPromise := AsyncFetchData(ctx, 451)
    // do other stuff while operation is not settled
    // once your ready to wait for data:
    myData, err := myDataPromise.Await(ctx)
    if err != nil {/* ... */}
}

FAQs

Package last updated on 28 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc