Skip to content

Specifying (async) generator behavior #18

Open
@legendecas

Description

@legendecas

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:

  1. 'first iter'/'second iter', which is the context when the generator's next() is invoked.
  2. 'init'/'init', which is the context when the generator is being constructed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions