luciotato / waitfor

Sequential programming for node.js, end of callback hell / pyramid of doom
MIT License
532 stars 29 forks source link

wait.for inside eval() #44

Closed KaMeHb-UA closed 7 years ago

KaMeHb-UA commented 7 years ago

That code throws an error "Callback called twice" but... there is no twice-called functions. Problem in eval()? But what can I do, if i can't exclude this stage? I MUST use wait.for inside eval()'ed functions. Error demo

var wait = require("wait.for")
var contents = 'write("You must wait 5 seconds before page loads...<br/>");\
var a = wait.for(function(callback1){\
    setTimeout(function(){\
        callback1(null, "Hell O MFs");\
    }, 5000);\
});\
exit(null, a);';
function route(){
    eval('function page(write,exit){' + contents + '}');
    var fakewrite = function(a){console.log(a)};
    wait.for(page,fakewrite);
}
wait.launchFiber(route);
luciotato commented 7 years ago

Sorry I can't help you. I'm not doing support for this.

On Mon, Aug 14, 2017 at 10:04 AM, KaMeHb-UA notifications@github.com wrote:

That code throws an error "Callback called twice" but... there is no twice-called functions. Problem in eval()? But what can I do, if i can't exclude this stage? I MUST use wait.for inside eval()'ed functions. Error demo https://runkit.com/embed/yz68zrdm3d1l

var wait = require("wait.for")var contents = 'write("You must wait 5 seconds before page loads...
");\var a = wait.for(function(callback1){\ setTimeout(function(){\ callback1(null, "Hell O MFs");\ }, 5000);});\exit(null, a);';function route(){ eval('function page(write,exit){' + contents + '}'); var fakewrite = function(a){console.log(a)}; wait.for(page,fakewrite); }wait.launchFiber(route);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/luciotato/waitfor/issues/44, or mute the thread https://github.com/notifications/unsubscribe-auth/ABreietSeFHI_w4VcgHP6jyVUJD-ndnnks5sYEXngaJpZM4O2Vxn .

KaMeHb-UA commented 7 years ago

It's bad.. Ok, I'll test one more way to get it works. Thanks for reply!

markcollinscope commented 7 years ago

Dear KaMeHb-UA.

Luciotato's wait.for module was a godsend to me. Solved so many problems. And it works great.

So great, in fact, that Nodejs 8 seems to have copied it [await].

So I'd (with respect) suggest you look at the documentation and your own code and try to work out the issue yourself.

Kind regards, Mark.