Created
October 25, 2020 22:54
-
-
Save dburles/6c2e5d1605f71e3311d92f73027e4f0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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