You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine you have a state that reads the user their current bank balance, and that looking up this balance is quick enough that you don't need to render any intervening twiml while the lookup is occurring, but slow enough that you can't do it synchronously and lock up your server. This might mean it takes 100ms or so, which is actually a really common query time.
In the current architecture, there's not really a good way to handle this, because the most natural place to do the lookup (the state's twimlFor) has to produce the twiml synchronously. So, instead, you have to create a state dedicated solely to doing the lookup that then transitionOuts (if it's a branching, non-renderable state) or uses the REST API (if its an async state) to go to the state you actually care about. This doesn't seem optimal.
One simple option, then, would be to allow twimlFor to return a promise, so the twiml can be computed asynchronously. That seems to make the program harder to reason about, though, because data can be loaded in more places (whereas right now its only set in transitionOut, by amending the session, and read in twimlFor; or read in transitionOut to decide where to branch). Another option might be to create a beforeRender function that returns a promise when its done, having updated the session, and then twimlFor isn't called until that resolves. That's a bit neater, but it's similar to the first option. Thought about from this perspective, though, the current backgroundTrigger starts to look a lot like afterRender, and twimlFor could be named render, giving a nice trio: beforeRender, render, afterRender.
The text was updated successfully, but these errors were encountered:
Imagine you have a state that reads the user their current bank balance, and that looking up this balance is quick enough that you don't need to render any intervening twiml while the lookup is occurring, but slow enough that you can't do it synchronously and lock up your server. This might mean it takes 100ms or so, which is actually a really common query time.
In the current architecture, there's not really a good way to handle this, because the most natural place to do the lookup (the state's twimlFor) has to produce the twiml synchronously. So, instead, you have to create a state dedicated solely to doing the lookup that then
transitionOut
s (if it's a branching, non-renderable state) or uses the REST API (if its an async state) to go to the state you actually care about. This doesn't seem optimal.One simple option, then, would be to allow
twimlFor
to return a promise, so the twiml can be computed asynchronously. That seems to make the program harder to reason about, though, because data can be loaded in more places (whereas right now its only set in transitionOut, by amending the session, and read in twimlFor; or read in transitionOut to decide where to branch). Another option might be to create abeforeRender
function that returns a promise when its done, having updated the session, and then twimlFor isn't called until that resolves. That's a bit neater, but it's similar to the first option. Thought about from this perspective, though, the currentbackgroundTrigger
starts to look a lot likeafterRender
, andtwimlFor
could be namedrender
, giving a nice trio:beforeRender
,render
,afterRender
.The text was updated successfully, but these errors were encountered: