Skip to content

Instantly share code, notes, and snippets.

@jaysoo
Created February 12, 2020 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysoo/4eb21671c0c7336dcbe5eebcac414b74 to your computer and use it in GitHub Desktop.
Save jaysoo/4eb21671c0c7336dcbe5eebcac414b74 to your computer and use it in GitHub Desktop.
const fetchUsers = createAsyncThunk(
"users/fetch",
(function () {
// use `p` to ensure promises are returned in order.
let p = Promise.resolve();
return () => {
// Wait for previous promise to resolve first to guarantee ordering.
return p.then(() => {
// Change binding to new API call.
p = usersAPI.fetchAll();
// Return current promise.
return p;
})
}
})()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment