Code Monkey home page Code Monkey logo

future's Introduction

#future

asynchronous combinator library for D

Futures are values yet to be computed. They are shared and thread-safe.

Futures receive a pending value with fulfill, and can actively forward the received value to callback delegates registered with onFulfill.

example: executing a function in another thread

If f :: A -> B, then async!f :: A -> Future!(Result!B).

Suppose f(a) = b and async!f(a) = c.

async!f will execute f in a separate thread when invoked.

While f is being computed, c.isPending.

If f succeeds, c.isReady and b == c.result.success.

If f throws, c.isReady and c.result.failure is inhabited with the caught error.

Attempting to read c.result before c.isReady is an error.

async!f can be made blocking at any time with c.await.

For convenience, c.await returns c so that c.await.result == c.result.

advanced usage

For a futures a and b, and arguments c...

a.then!f(c) returns a future which contains f(a.result, c) when a is ready

a.next!f(c) chains two futures (a and f(a.result, c)) into a single future

if a.result is also a future, sync(a) joins the inner and outer futures of a (like a lazy await.result.await)

when(a,b) is a future Tuple(a.result, b.result), ready when both a and b are ready

race(a,b) is a future Union(a.result, b.result), ready when either a or b are ready

detailed documentation and examples

is contained in the unittest

with dub

dependency "future" version="0.1.0"

future's People

Contributors

vl-01 avatar

Stargazers

Andrés Brugarolas avatar  avatar Kaden Thomas avatar  avatar martin mauchauffée avatar Zhao Puming avatar Pradeep Gowda avatar Jonas Drewsen avatar Denis Feklushkin avatar

Watchers

James Cloos avatar  avatar  avatar

future's Issues

TypeMap undefined

It seems it shoud be included in universal. However, the lastest code for universal has not commited yet.

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.