javascript - dynamically creating function with promise infinite loop mocha -
8 hours later....
not sure happened, realized when wrote file root directory of project, got stuck in infinite loop. anywhere else, worked fine.
//update
still working on this. missed superbowl. update have writefilesync gives exact same error.
i've been banging head on 1 while now.
promisefunction = [promisefunction1, promisefunction2, promisefunction3].reduce((oldfunction, newfunction)=>{ return function (){ return oldfunction().then(()=>{ return newfunction() }) } }
when try test promisefunction(), infinite test loop (all of tests test promisefunction keep firing in perpetuity)
the catch however, promise function screwing promisify(fs.writefile)
when try using different promise function, promisify(fs.readfile)
, works fine.
when console log difference between readfile , writefile promises, there respective results:
//readfile readfilepromise promise { _bitfield: 67108864, _fulfillmenthandler0: undefined, _rejectionhandler0: promise { _bitfield: 0, _fulfillmenthandler0: undefined, _rejectionhandler0: undefined, _promise0: undefined, _receiver0: undefined }, _promise0: undefined, _receiver0: undefined } //writefile writefilepromise promise { _bitfield: 67108864, _fulfillmenthandler0: undefined, _rejectionhandler0: promise { _bitfield: 0, _fulfillmenthandler0: undefined, _rejectionhandler0: undefined, _promise0: undefined, _receiver0: undefined }, _promise0: undefined, _receiver0: undefined }
i not understand why getting infinite loop writefile. please god help.
if want series perhaps returning function not want. because nothing going called. instead leverage promise chaining:
[promisefunction1, promisefunction2, promisefunction3] .reduce((memo, next) => memo.then(next), promise.resolve());
Comments
Post a Comment