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

getPromise() in atom effects does not resolve #2314

Open
phjardas opened this issue Apr 13, 2024 · 0 comments
Open

getPromise() in atom effects does not resolve #2314

phjardas opened this issue Apr 13, 2024 · 0 comments

Comments

@phjardas
Copy link

phjardas commented Apr 13, 2024

Consider the following scenario where an atom effect tries to get the value of another atom.

const oneAtom = atom({
  key: "one",
  effects: [
    ({ setSelf }) => {
      setTimeout(() => setSelf("ok"), 1000);
    },
  ],
});

const twoAtom = atom({
  key: "two",
  effects: [
    ({ getPromise, setSelf }) => {
      getPromise(oneAtom)
        .then((value) => setSelf(value))
        .catch((error) => console.error("error in two:", error));
    },
  ],
});

The atom one starts in loading state and only resolves after a second.

I'd expect the promise returned from getPromise(oneAtom) to be initially pending (which it does) and eventually resolve with the value of the atom one when that one resolves. However, the returned promise remains in pending state forever; neither the then nor the catch callback are ever called.

Note that I've intentionally omitted the cleanup logic for setTimeout to keep the example concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant