Skip to content
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

Looking up data before render #7

Open
ethanresnick opened this issue Dec 25, 2016 · 0 comments
Open

Looking up data before render #7

ethanresnick opened this issue Dec 25, 2016 · 0 comments

Comments

@ethanresnick
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant