4 ms·
PostScriptum.js – A new way to manage callback hell without promises
- ubertaco 11y agoIt advertises that it's "without promises", but then implements a remarkably Promise-like API: PS.create(someAsyncFunction, ['argOne'], callback1) .then(callback2) .then(callback3) .run(); Really the only obvious API difference there is that starting the chain is uglier, and there's a "run()" method that has to be invoked before kicking things off. Presumably, this also doesn't handle errors as nicely as Promises do either; I didn't see anything about error handling in a quick-skim.
- cleod9 11y agoThe reason the run() method exists is to avoid how normal promises automatically run on the next event loop tick after then() is called. It allows more flexibility by separating the definition of a "promise" chain from the actual execution of the chain. Also I consciously excluded automatic error handling, since I personally disagree with how promises consume errors that are unmanaged (can be a debugging nightmare!). I prefer the opposite, where errors are managed by the developer and not the library. I totally appreciate the feedback though, I don't think this can replace promises but it might be useful for people who want an alternative.
- cleod9 11y agoI should also add that this library eliminates the need for plugins such as this: https://www.npmjs.com/package/webdriver-sync https://www.npmjs.com/package/webdriver-sync