using callback pattern for asynchronous code #71
Comments
|
I personally wholeheartedly agree with this. It's the single biggest thing that bugs me about using this module personally: returning false on every single Intent handler is very non-standard and I have to comment every one to explain why it's there. I think handling promises as return values would be ideal, and an alternate mocha-style |
|
I agree, this is a bit annoying, but I put it in there originally for backwards compatibility. In the previous releases, handlers were required to be sync. Allowing for the return of an explicit Promise (as opposed to false) was in my plans but I never got to it. I also wanted to keep it VERY simple to implement the most basic use cases, which are sync handlers. In that case, the developer never needs to worry about creating or fulfilling Promises or remembering to call a 'done' function. Just write some simple code and it works. My thought was that only more advanced functionality will be async in handlers, and at that point the developer can learn the additional requirements for that scenario. I didn't want to use a callback, because Promises are supposed to avoid that ugly syntax. And forcing a callback parameter in method signatures makes it harder to add parameters later if necessary. Promises are the way to go, IMO. |
|
Mocha uses some magic to make the That way you get the best of both worlds: by default it's all sync, unless you define the However, that whole |
gurpreetatwal
commented
Jun 6, 2016
•
|
Agreed, I'm all for promises. In my use of the library I used promises as well. Supporting the return of a promise shouldn't be too hard no? It can be treated similar to the return false check. Check if the return object is a promise and if so attach a then which either calls In terms of the |
OverloadUT
referenced
this issue
Jun 20, 2016
Closed
Configuration option to turn off automatically sending a response unless the intent returns false #73
gurpreetatwal
commented
Jul 18, 2016
|
any updates on this? I can submit a PR if you would like |
|
@gurpreetatwal Would love to see a PR. You got my attention now. |
dblock
added the
new feature
label
Dec 16, 2016
gurpreetatwal
commented
Dec 16, 2016
|
I'll start working on it in about a week. Are you taking over the maintenance of this repo now? I'd love to help with that if you like |
|
Thanks. I'm just helping out, I do have committer rights and such. I know @matt-kruse is considering making an org and expanding the circle of friends, so looking forward! |
dblock
referenced
this issue
Jan 12, 2017
Closed
res.say() doesn't work when in .then() of returned promise. #122
gurpreetatwal
commented
Jan 20, 2017
|
@dblock I now have time to start working on this task, however before I begin I wanted to plan the task out a bit more. What exactly are we planning to achieve?
|
|
This is just my 2c, but I think we don't have to support |
gurpreetatwal
commented
Jan 20, 2017
|
I'm fine with only supporting promises, it makes things cleaner in the long run. However since In terms of the @OverloadUT @chearmstrong any thoughts? |
ajcrites
added a commit
to ajcrites/alexa-app
that referenced
this issue
Jan 27, 2017
|
|
ajcrites |
04678a3
|
ajcrites
referenced
this issue
Jan 27, 2017
Merged
Support Promises/callbacks from request handlers (#71) #133
ajcrites
added a commit
to ajcrites/alexa-app
that referenced
this issue
Jan 27, 2017
|
|
ajcrites |
b6e4ed3
|
ajcrites
added a commit
to ajcrites/alexa-app
that referenced
this issue
Jan 27, 2017
|
|
ajcrites |
f7b5a1e
|
|
Closing via #133. |
dblock
closed this
Jan 27, 2017
chearmstrong
commented
Jan 27, 2017
|
Just seen this (sorry) but #133 seems like a good solution to this. |
gurpreetatwal commentedJun 5, 2016
As of right now, the only way to do asynchronous things in the intent handler is to return false and then call res.send(). Although this works and is documented in the readme, it is different from the commonly used design patter of using a callback function as the last parameter. One example would be mocha and the 'done' pattern.
Also since internally the request handler uses a promise it would be nice to be able to return a promise from the intent handler, this would also allow for another commonly used pattern of writing asynchronous code.
Thoughts?