Skip to content

Instantly share code, notes, and snippets.

@dburles
Created October 25, 2020 22:54
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 dburles/6c2e5d1605f71e3311d92f73027e4f0c to your computer and use it in GitHub Desktop.
Save dburles/6c2e5d1605f71e3311d92f73027e4f0c to your computer and use it in GitHub Desktop.
// https://codesandbox.io/s/createsuspendevent-7yuzl?file=/src/Test.js
const createSuspendEvent = (fn) => {
return () => {
createResource(() => {
return new Promise((resolve) => {
fn((cleanup) => {
if (typeof cleanup === 'function') {
cleanup();
}
resolve();
});
});
})(fn);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment