google / chained-promise Goto Github PK
View Code? Open in Web Editor NEWFunctional programming tools for recurring promises
License: Apache License 2.0
Functional programming tools for recurring promises
License: Apache License 2.0
This will accept an accumulation function of type {function(<U>, <V>) : Promise.<U>}
, and turn ChainedPromise.<U>
into ChainedPromise.<{data: V, next: ChainedPromise}>
This is an intermediate step in implementing reduce
. A missing puzzle is how to support termination from ChainedPromise
For initial implementation, we can wrap the function around with Promise.resolve().
The idea is to have the promise resolved once the callback function is called. For example, if we have a callback function defined as follows:
const cb = adaptedPromise.adaptToCallback();
someAsyncOp('abc','def', cb);
when someAsyncOp
calls up on cb, adaptedPromise will be resolved into:
{
data: [arg1, arg2, ...],
next: nextPromise
}
nextPromise
will be resolved next time cb
is called upon.
Node 6.5.0 doesn't seem to play nicely with subclasses of Promise when constructing one. Opened an issue with nodejs: nodejs/node#8474
Functions such as .map()
and .flatMap()
can further be extended to provide an eDSL for easy data joining operation. For example, if we have a person's book records with books
field having references to another API endpoints:
{
"name": "John",
"id": "12345",
"books": [1277, 1255, 1290, 3003]
}
we want to be able to specify how to further join the refs. One possible way would be:
ChainedPromise.of(rq("/user/31337/books"))
.join({books: [(v) => rq("/book/" + v)]})
This code should be equivalent to doing:
ChainedPromise.of(rq("/user/12345/books"))
.flatMap((v) =>
ChainedPromise.of(Promise.all(v.books.map((book) => rq("/books/" + book))))
.map((books) => {
v.books = books;
return v;
}));
Open questions:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.