Skip to content

Wait for afterCreate flow to finish #1673

Answered by EmilTholin
EmilTholin asked this question in Q&A
Discussion options

You must be logged in to vote

You can store the promise that is the result of the afterCreate flow in a volatile state variable, and add a separate method to the model that runs the code once the afterCreate promise has resolved:

const Model = types.model("Model", {}).actions((self) => {
  let afterCreatePromise;

  const afterCreate = flow(function* () {
    try {
      yield persist("xxxxxxxxx", self, {
        storage: AsyncStorage,
        jsonify: true,
      });
    } catch (error) {
      // ...
    }
  });

  return {
    afterCreate() {
      afterCreatePromise = afterCreate();

      return afterCreatePromise;
    },
    clear: flow(function* () {
      yield afterCreatePromise;

      // do some clearing...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by EmilTholin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant