5 ms·
Here's Chris' comment from when this was posted (but didn't make it to the front page) yesterday: --- malgorithms 22 hours ago | link I think the great thing
by jashkenas 12y ago
Here's Chris' comment from when this was posted (but didn't make it to the front page) yesterday:
---
malgorithms 22 hours ago | link
I think the great thing about IcedCoffeeScript + the ESC library is how it fits into more complicated flow logic, while allowing easy refactoring. Max doesn't really get into the otherwise impossible examples in his post.
Even if you're firing off RPC's awaiting in the middle of a loop or switch statement, you can move logic around just by shifting individual lines. Consider how simple this looks:
for user_id in user_ids
await load_user user_id, esc defer user
user.whatever()
# etc., with user
Writing that in plain Coffee or JS is impossible; using a pure async library is sort of possible but impossible to refactor.
- malgorithms 12y agoTo elaborate, a nice thing about Iced is the simplicity, even inside flow logic, to refactor async code. # serial for uid, i in uids await load_user uid, defer users[i] All I do is move the await: # concurrent await for uid, i in uids load_user uid, defer users[i] As you can imagine, this would be radically different JavaScript, yet it's (1) easy to read Coffee, (2) easy to refactor, and (3) runs on any browser. The ES6 stuff is new, and I can't use it because I'm writing for both Node and the browser, but can someone tell me how the above refactor would go?
- aikah 12y agoYou cant really do that in ES6.You'd have to use a co-routine framework (and a "thunkifier") and a generator that would yield some stuff. something like co(function *(){ for(i in uids){ users[i] = yield thunkify(load_users)(uids[i]); } }); While generators are useful, they dont make async code look like sync code.