Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jc2k/whorl
Write async code synchronously in JavaScript
https://github.com/jc2k/whorl
Last synced: about 1 month ago
JSON representation
Write async code synchronously in JavaScript
- Host: GitHub
- URL: https://github.com/jc2k/whorl
- Owner: Jc2k
- Created: 2010-03-21T19:12:08.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2010-03-24T23:22:23.000Z (over 14 years ago)
- Last Synced: 2024-04-16T01:44:36.947Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
whorl is just a bit of code to play with when i'm bored. It's like a mini version of the core bits of Twisted, but in JavaScript.
It has 2 ideas about what it wants to be when it grows up. It would like to be part of the GNOME desktop, helping users write asynchronous code with a simple almost synchronous coding style.
var print_contents = Defer.async( function (file) {
var in_stream = yield file.read ();
var bytes = yield in_stream.read (4096);
while (bytes) {
print (bytes);
bytes = yield in_stream.read (4096);
}
});It would also like to be part of the wave of JavaScript on the server - it would like to grow up to be like its big brother, Twisted.
var handle_POST = Defer.async( function () {
try {
var page = yield WebClient.getPage ("http://www.google.com/search?q=turnips");
} catch (e if e instanceof HTTP404) {
print ("Error callbacks in async code even get mapped to exceptions :D");
}do_stuff_to_page (page);
Defer.returnValue (page);
});Of course, it works the same for both use cases and the difference is just the integration wrappers built on top of the respective client and server side frameworks...