-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Promises #55
Comments
I suggest using https://github.com/thunks/thunks. |
Looks cool... I need to evaluate that more deeply to understand it. I know that promises are a higher level of abstraction than control flow like async.js, which is why I wanted to go that direction. What is the relationship between thunks and promises? |
|
Okay, I'm beginning to wrap my head around this. Any asynchronous (or synchronous) function can be wrapped in a thunk to represent a deferred value with a well-defined interface for accessing the result. It's basically just done as a function instead of a Promise object. I'm still a bit unclear on why you would use Thunks over Promises or vice versa. Googling "thunks vs promises" yielded surprisingly little. It seems like thunks are a bit lower level than promises. Consequently they are more lightweight, but are less robust in some situations. "Thunk will not catch exception within execute function (from thunk( executeFn ))" "You may notice that this will lead the execution of cb be indeterministic (aka. zalgo). Then following code will help you to check if it's sync or async... you can always convert thunk function to promise if you want to ensure zalgo-free." "If you don’t like or understand this, just use promises. Promises are almost certainly a better choice for application code. Thunks are only good as a low-level primitive used internally by Koa because they don’t involve any particular promises library." "Comparing thunks to promises generally: they’re not directly interchangable as they’re not equivalent in behavior. Promises are vastly more capable and trustable than bare thunks." With efficient Promise libraries like bluebird that have all, seq, etc as well as robust error handling, I feel like there's no reason not to use Promises. I appreciate your offer to refactor using thunks, and I'm wondering what your thoughts are on the Promise advantages mentioned above. Thanks! -Raine |
there is something wrong in https://github.com/gyson/gocsp-thunk:
|
Okay, perhaps "Comparing thunks to promises generally: they’re not directly interchangable as they’re not equivalent in behavior. Promises are vastly more capable and trustable than bare thunks." I am just wanting to make sure I properly understand the differences/tradeoffs. |
You can try Promise first~ |
Okay. Thanks for your great input! Good to be thinking about this stuff On Mon, Mar 23, 2015 at 8:52 PM, Yan Qing notifications@github.com wrote:
|
Promises are in! ^_^ |
Callbacks are so 2010.
The text was updated successfully, but these errors were encountered: