Open
Description
Related: nodejs/node#42237, open-telemetry/opentelemetry-js#2951
Should a generator or an async generator capture the async context when being created? Given:
const context = new AsyncContext();
async function* gen(context) {
await Promise.resolve();
// ???
console.log(context.get());
yield;
await Promise.resolve();
// ???
console.log(context.get());
}
let g;
context.run('init', () => {
g = gen(context);
});
await context.run('first iter', async () => {
await g.next();
});
await context.run('second iter', async () => {
await g.next();
});
The output options could be:
'first iter'
/'second iter'
, which is the context when the generator'snext()
is invoked.'init'
/'init'
, which is the context when the generator is being constructed.
Metadata
Metadata
Assignees
Labels
No labels