-
Notifications
You must be signed in to change notification settings - Fork 78
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
adding minutes from 2018-01-24 meeting #141
adding minutes from 2018-01-24 meeting #141
Conversation
The example I had in mind is a pattern I am starting to see quite frequently with a lazily initialized promise being used as a cache of some async data. const app = express();
let authTokenPromise;
app.get('/', (req, res) => {
if (!authTokenPromise) {
// lazily acquire an auth token.
authTokenPromise = fetch('some url');
}
authTokenPromise.then(() => {
// business logic.
// What is my context here?
});
}); The way The other link that might be interesting is this: othiym23/node-continuation-local-storage#114. That was a special case of the general problem above. There is some more discussion on this topic here: othiym23/node-continuation-local-storage#64 |
I've also seen promises passed around with callbacks attached in a multi-consumer style, which makes the graph confusing because everything points to the creation point of the promise, not the insertion point of the callback. |
@Qard - can you post some short example code? I'm trying to work on visualizations of the graphs produced by different coding patterns to help everyone get on same page. |
A good example I've seen is people replacing the delayed routing body-parser approach typical in express with a stored promise, for better performance. app.use((req, res, next) => {
req.body = parse(req) // returns a promise of the result of the consumed stream
next()
}) Once that middleware is run, the |
@ofrobots - check out example code & visualization here: https://mike-kaufman.github.io/async-context-definition/examples/lazilyInitializedPromise/slideShow/async-context.html. Given our model & graph shown there, you should maintain correct context. Feel free to open an issue in https://github.com/mike-kaufman/async-context-definition/issues if you think anything is missing and/or incorrect. |
@mike-kaufman that model doesn't match my intuition. It also doesn't match all the potential mental models developers can have, as listed in othiym23/node-continuation-local-storage#64. My intuition is that (Let's extract this into a separate issue -> #143) |
@Qard - visualization of your example ishere. Sorry for delay, had this on my machine & then was out of town. Please let me know if you have any questions. Note that your example highlights an issue, which is where are the logical continuation points and how are those indicated to the user? This example is currently inconsistent with the simpleExpress example. I'll need to rectify these. |
No description provided.