4 ms·
Personally, I love the way xmlhttprequest handles asynchrony. Every process/function that deals with i/o,db,etc should provide at least two events onReady and
by Kilimanjaro 17y ago
Personally, I love the way xmlhttprequest handles asynchrony.
Every process/function that deals with i/o,db,etc should provide at least two events onReady and onError (drop the 'callback' and 'errback' aberrations) and leave JS as pure as it is right now.
Other events may be used like onProgress, onLoad, etc.
- Kilimanjaro 17y agoFor example, usinging XHR model: file = new File.Reader() file.onReady = printfile file.onError = showerror file.onProgress = showprogress file.read('myfile.txt') Not restricted to callback and errback only, more events may be available according to the process being executed, keeping JS as natural as possible. Hacks can be added on top to handle parallel or chainable process. One last thing, make the process asynchronous by default and set a property to false to make it synchronous, no need to force a last parameter to a function. file.async = false file.read('myfile.txt')