repeatingbeats / invoke Goto Github PK
View Code? Open in Web Editor NEWJS flow control micro-library
License: MIT License
JS flow control micro-library
License: MIT License
Hi!
I was wondering..
Its possible to implement Invoke running in a browser? (without NodeJS, only javascript client)
It would be interesting!
Thanks
invoke has nice syntax for controlling the flow of individual anonymous functions, but it lacks semantics for operating on arrays of functions.
I'm currently thinking of an API that looks like:
// batch of sequential functions
invoke(batch).sequentially().rescue(function (err) {
// error handler
}).end(initial, function (results) {
// success handler
});
// batch of parallel functions
invoke(batch).inParallel().rescue(function (err) {
// error handler
}).end(initial, function (results) {
// success handler
});
// complex flow
invoke(function (data, callback) {
// ...
}).then(sequentialBatch).sequentially().then(function (data, callback) {
// ...
}).then(parallelBatch).inParallel().rescue(function (err) {
// error handler
}).end(initial, function (results) {
// success handler
});
example:
var invoke = require('./../lib/invoke')
, start
// Parallel execution of three slow async functions
start = Date.now()
invoke(function (data, callback) {
setTimeout(function(){ callback('error 1') }, 100)
}).and(function (data, callback) {
setTimeout(function(){ callback('error 2') }, 100)
}).and(function (data, callback) {
setTimeout(function(){ callback('error 3') }, 100)
}).rescue(function (err) {
console.error(err)
}).end(null, function (data) {
console.log('Parallel execution took: ' + (Date.now() - start))
})
Result: resque called 3 times, not once
error 1
error 2
error 3
To fixed put this line to top (in invoke.js)
78: if (self._err) return
after 71: fn(passed, function (err, data) {
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.