haxetink / tink_await

Haxe async/await
MIT License
58 stars 15 forks source link

Use Promise #17

Closed kevinresol closed 7 years ago

kevinresol commented 7 years ago

This makes the transformed function returns Promise<T> instead of Surprise<T, Dynamic>. Mainly because Promise has richer API, IMO. I use Promise everywhere now.

Since Promise<T> is essentially Surprise<T, Error>, that means errors thrown are wrapped in Error instances, and the data field gets extracted when the error is caught. So if some codes throws a string, the catch block should also catch a string. (Closes #4) If I understand correctly, the Error instance will not get destructured in the throw-catch waterfall but only at the end user's catch block, (correct me if I am wrong). If that is true, the performance impact should be minimal.

Seems passing the tests.