Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What's being discussed wrt promises?

(I don't like promises and would like to see it go away. Sadly too many specs have adopted it already)



I don't like promises and would like to see it go away

You could always just... not use them.


Most coders have to use and extend a lot of other peoples' code, so if everybody else is using them then you have to deal with it...


Why, what's the alternative? If you're thinking of using something like a generator, OK.

If you're in favor or callbacks, you're doing it wrong.


Generators are the solution.

I use promises and like them, but generators are a LOT nicer. I've been playing around with KoaJS and I'm amazed with it. I find that overall it makes code a lot easier to read, write, and understand.

On top of that, it give you sane stack-traces!

I'm not certain if this is correct, but from what I can gather, you can yield on a promise and if you resolve it successfully you get the value directly and if you resolve it as a failure, it will throw an error.

The example I like to show people is this: https://www.dropbox.com/s/06zy52m8x0lllzn/Screenshot%202014-... It's the controller for a user's registration, where the thrown error is an object of invalid fields submitted.


What do you think is a better alternative?


There are some very interesting things you can do with generators in regards to asynchronous flow control. Personally I'm in favor of the Promises, however. Unfortunately some current implementations are broken in terms of error handling. Chrome just swallows exceptions that happen in Promises, in a lot of cases.


Generators are no fun to work with so you want a library. Promises won't require a library so i'll use that.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: