Comments (4)
No, I just tried it and that code doesn't work. The book is almost 5-1/2 years old. I don't recall if that approach did work at the time (it probably did because I assume I would have tested it), but to be honest, I don't even recall having written this example. And the documentation for the library doesn't document that capability. Shrugs. It's possible it may work in an older version of asynquence from 5+ years ago.
What's clear is asynquence definitely doesn't currently support extending sequences the way that example is depicting, but it should support it in the way I've suggested above.
OK!TKS for your reply,that made everything clear.
from asynquence.
As far as I recall, dynamically adding steps to an iterable-sequence instance during its iteration doesn't cause those steps to be recognized
However, the runner(..)
plugin does support a way to dynamically add more "steps" to its run, by way of adding additional iterable sequences. Here's a test from the contrib test-suite that shows using token.add(..).
And here's a codepen demo fixing your code to work as you asked:
let steps = ASQ.iterable()
.then(function STEP1(token){
let msg = token.messages[0];
msg = msg + ' STEP1';
// add another sequence of steps to the end of this run
token.add(
ASQ.iterable().then(function STEP3(msg){
return msg + ' STEP3';
})
);
return msg;
})
.then(function STEP2(msg){
return msg + ' STEP2';
});
ASQ("ASQ")
.runner(steps)
.val(function(msg){
console.log(msg);
});
// ASQ STEP1 STEP2 STEP3
from asynquence.
As far as I recall, dynamically adding steps to an iterable-sequence instance during its iteration doesn't cause those steps to be recognized
However, the
runner(..)
plugin does support a way to dynamically add more "steps" to its run, by way of adding additional iterable sequences. Here's a test from the contrib test-suite that shows using token.add(..).And here's a codepen demo fixing your code to work as you asked:
let steps = ASQ.iterable() .then(function STEP1(token){ let msg = token.messages[0]; msg = msg + ' STEP1'; // add another sequence of steps to the end of this run token.add( ASQ.iterable().then(function STEP3(msg){ return msg + ' STEP3'; }) ); return msg; }) .then(function STEP2(msg){ return msg + ' STEP2'; }); ASQ("ASQ") .runner(steps) .val(function(msg){ console.log(msg); }); // ASQ STEP1 STEP2 STEP3
Thank you,I got it.
BTW,these is an example in your book ASYNC PERFORMANCE Appendix B like below:
var steps=ASQ.iterable();`
.then(function STEP1(token){
var url=token.messages[0].url;
if(token.messages[0].format){
steps.then(token.messages[0].format);
}
return request(url);
})
.then(function STEP2(resp){
if(/x1/.test(resp)){
steps.then(function STEPS5(text){
return request(
"http://some.url.4/?v=" + text
);
});
}
return ASQ().gate(
request("http://some.url.2/?v=" + resp,
request("http://some.url.3/?v=" + resp
);
})
.then(function STEP3(r1,r2){ return r1+r2;});
var main=ASQ({
url:"http://some.url.1",
format:function STEP4(text){
return text.toUpperCase();
}
})
.runner(steps2)
.val(function(msg){
console.log(msg);
});
Is that code work?Thanks again.
from asynquence.
No, I just tried it and that code doesn't work. The book is almost 5-1/2 years old. I don't recall if that approach did work at the time (it probably did because I assume I would have tested it), but to be honest, I don't even recall having written this example. And the documentation for the library doesn't document that capability. Shrugs. It's possible it may work in an older version of asynquence from 5+ years ago.
What's clear is asynquence definitely doesn't currently support extending sequences the way that example is depicting, but it should support it in the way I've suggested above.
from asynquence.
Related Issues (20)
- Sequence's order of execution may be wrong in some cases HOT 10
- `runner(..)` plugin bug w/ multiple generators
- ARRAY_SLICE is not defined. HOT 4
- Combining Generators with Promises Using Asynquence HOT 2
- pass all message in map()
- improve `wrap(..)`
- Thanks for asynquence HOT 1
- async map HOT 4
- JSBin examples not working HOT 3
- Babel 6: missing ) after argument list (asq.src.js line 66) HOT 6
- loop over an array in series? HOT 6
- Continue onerror fail HOT 2
- [question] why do u use setImmediate not process.nextTick ? HOT 4
- contrib: fix wrapped generators and arguments
- test-extensions are in contrib for some reason HOT 3
- [README]: Enlarge build section to be about contrib (Maybe), add 'Contributing' section HOT 4
- autod error
- ASQ.iterable() is not a function... HOT 5
- ES6 asynquence-contrib importing issue HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asynquence.