Skip to content

Question: actor with promise doesn't return output? #4632

Answered by davidkpiano
persona0591 asked this question in Q&A
Discussion options

You must be logged in to vote

There is nothing that's "awaiting" that promise - createActor(main).start() will just return immediately.

You can use the toPromise(...) helper:

import {
  toPromise,
  // ...
} from 'xstate';

// ...
export async function run() {
  // ...

  const actor = createActor(main);

  actor.start();

  await toPromise(actor);
}

See the docs for more info.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@persona0591
Comment options

Answer selected by persona0591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants