Git Product home page Git Product logo

Comments (4)

akixxx1982 avatar akixxx1982 commented on June 4, 2024 1

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.

getify avatar getify commented on June 4, 2024

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.

akixxx1982 avatar akixxx1982 commented on June 4, 2024

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.

getify avatar getify commented on June 4, 2024

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)

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.