Kal – a clean JavaScript alternative without callbacks
71–80 of 130 posts
Re: Kal – a clean JavaScript alternative without callbacks
#72This is a project I've been working on in my spare time for a while now and I've finally decided to throw it out there and get some feedback. Do you think the 'wait for' callback syntax is useful? What big features do you think are missing?
Re: Kal – a clean JavaScript alternative without callbacks
#73Re: Kal – a clean JavaScript alternative without callbacks
#74Earlier quoted context omitted.
There is no need for hacks, just run node with the `--harmony` flag to get yield support today. Q is a huge, monster library. It's 2x the size of caolan/async, which is already bloated. I personally think it's better to use https://github.com/mbostock/queue or another small, understandable library.
If you're taking about node, what difference does it make how large the library is?
Re: Kal – a clean JavaScript alternative without callbacks
#75This is a project I've been working on in my spare time for a while now and I've finally decided to throw it out there and get some feedback. Do you think the 'wait for' callback syntax is useful? What big features do you think are missing?
Looks pretty good! I like it. To be honest I will not use it in my projects. I prefer using ES6 syntax for this problem when it's available.
Re: Kal – a clean JavaScript alternative without callbacks
#76Earlier quoted context omitted.
I also vote for 'await' here. The 'wait for friends from' construct looks too much like BASIC for my liking. It's not clear which terms are built into the language ('wait', 'for', 'from') and which are not ('friends'). Also, since the eventual result of that line is an assignment to 'friends', using the existing = operator makes the language more consistent.
Thanks for the feedback. It seems like a lot of people would prefer a more normal looking assignment. If you get a chance (and use TextMate or Sublime Text), please give syntax highlighting a try ( https://github.com/rzimmerman/kal.tmbundle )!
Re: Kal – a clean JavaScript alternative without callbacks
#77For this Kal code:
task getUserFriends (userName)
wait for user from db.users.findOne {name:userName}
wait for friends from db.friends.find {userId:user.id}
return friends
would become: task getUserFriends (userName)
user ..= db.users.findOne {name:userName}
friends ..= db.friends.find {userId:user.id}
return friendsRe: Kal – a clean JavaScript alternative without callbacks
#78Re: Kal – a clean JavaScript alternative without callbacks
#79For the curious, the equivalent example from the OP using promises[1]: function getUserFriends(userName) { return db.users.findOne({ name: userName }).then(function (user) { return db.friends.find({ userId: user.id }); }); } [1]: http://promises-aplus.github.io/promises-spec/
It's more obvious if you have multiple levels. function getUserFriends(userName) { return db.users.findOne({ name: userName }) .then(function (user) { return db.friends.find({ userId: user.id }); }) .then(function (friends) { return somethingAsync(friends); }); }
Re: Kal – a clean JavaScript alternative without callbacks
#80It appears to be very similar to icedcoffeescript: http://maxtaco.github.io/coffee-script/