Skip to content
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

Parent task might get canceled before the child task #13

Open
MartinMalinda opened this issue Aug 1, 2020 · 0 comments
Open

Parent task might get canceled before the child task #13

MartinMalinda opened this issue Aug 1, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@MartinMalinda
Copy link
Owner

When a task calls another tasks, it might do something like this, perhaps when doing an optimistic update:

export function useFollowTask(user) {
  const saveTask = useSaveUserTask();
  const followTask = useTask(function* (signal) {
    const newState = store.toggleSomeState(user);
    try {
      yield saveTask.perform({
       user
      });
    } catch (e) {
      store.toggleSomeState(user); // toggle back
      notifyError({
        title: 'Action was unsuccessful',
        text: e.message,
      });
    }
  }).drop();
}

On unMount the followTask might get cancelled before the saveTask and therefore, upon unMount cancelation the catch is not invoked. In this example, the optimistic update then does not get reverted.

Since saveTask is declared before followTask it should be cancelled first, but probably the order is not reliable enough.

Workaround for this particular case:

    signal.pr.catch(() => {
      store.toggleProfileFollowState(profile);
    });

But it shouldn't be needed.

@MartinMalinda MartinMalinda added the bug Something isn't working label Aug 1, 2020
@MartinMalinda MartinMalinda pinned this issue Aug 1, 2020
@MartinMalinda MartinMalinda unpinned this issue Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant