Coder Social home page Coder Social logo

goobird's Introduction

GooBird

Build Status

Write elegant asynchronous code using promises.

Features

Easily create promises

p := promise.Create(func() (interface{}, interface{}) {
  time.Sleep(100 * time.Milliseconds)
  return 42, nil
})

fmt.Println("Waiting...")

x,_ := p.Wait()

fmt.Println("x =", x)

prints

Waiting...
x = 42

Use of Then to chain promises

x,err := promise.Create(func() (interface{}, interface{}) {
  return 42, nil
}).Then(func(res interface{}) (interface{}, interface{}) {
  x := res.(int)
  return x * 2, nil
}).Wait()

Nest promises (works in Then too)

x,err := promise.Create(func() (interface{}, interface{}) {
  return promise.Create(func() (interface{}, interface{}) { return 42, nil }, nil
}).Then(func(res interface{}) (interface{}, interface{}) {
  x := res.(int)
  return x * 2
}).Wait()

Run arrays/slices of promises

x,err := promise.Create(func() (interface{}, interface{}) {
  return [...]*SPromise{
    Create(func() (interface{}, interface{}) { return 1, nil }),
    Create(func() (interface{}, interface{}) { return 2, nil }),
    Create(func() (interface{}, interface{}) { return 3, nil }),
  }, nil
}).All().Wait()

Fast

Uses a single GoRoutine per promise to run serial links in the chain and uses metuxes instead of channels to synchronize the promises.

Todo

Features

  • Each: Run a function on all items of an array and return an array
  • Map: Run a function on each item of a map and return a map, order not guarenteed
  • Reduce: Run a function to reduce an array to a single value, order not guarenteed
  • Filter: Run a function to filter an array to contain only specific values

Improvements

  • Documentation
  • License

goobird's People

Contributors

andrewcurioso avatar

Stargazers

 avatar  avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.