diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..fb4a17f --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1,3 @@ +import { nextFrame } from './util'; + +export { nextFrame }; diff --git a/src/lib/util.ts b/src/lib/util.ts new file mode 100644 index 0000000..fee8c0e --- /dev/null +++ b/src/lib/util.ts @@ -0,0 +1,11 @@ +/** + * Returns a promise that settles after the next frame renders. Useful for spacing synchronous + * work on the main thread. + */ +const nextFrame = () => { + return new Promise((resolve) => { + requestAnimationFrame(() => resolve()); + }); +}; + +export { nextFrame };