stync
Ever have this happen? You've got a bunch of asynchronous code that includes calls to console.log
(or process.stdout.write
); and it gets all jumbled because your callbacks fire in non-deterministic order.
This is just a little library to make things a bit more orderly.
Usage
var async = http = stync = ; var urls = "http://www.google.com" "http://www.yahoo.com" "http://www.amazon.com" "http://www.stackoverflow.com" "http://www.reddit.com" "http://www.github.com" "invalid URL"; async;
In the above example, all URLs are requested in parallel. Suppose a response is received from the last URL first. Everything will still display properly because each message
does not write itself to process.stdout
until its predecessor has called end
. In effect, messages "wait their turn" so that line-by-line the console output makes sense:
Fetching "http://www.google.com"... received response (200)... read 44887 bytes
Fetching "http://www.yahoo.com"... received response (200)... read 92645 bytes
Fetching "http://www.amazon.com"... received response (200)... read 170218 bytes
Fetching "http://www.stackoverflow.com"... received response (301)... read 148 bytes
Fetching "http://www.reddit.com"... received response (200)... read 111658 bytes
Fetching "http://www.github.com"... received response (301)... read 0 bytes
Fetching "invalid URL"... Error: connect ECONNREFUSED