@thi.ng/transducers-async
Version:
Async versions of various highly composable transducers, reducers and iterators
28 lines (27 loc) • 521 B
JavaScript
import { source } from "./source.js";
const raf = (opts) => {
let frame = 0;
let t0 = opts?.t0 || 0;
let isClosed = false;
const gen = source();
gen.close = () => {
isClosed = true;
gen.write(void 0);
};
const update = (t) => {
if (isClosed) return;
if (opts?.timestamp) {
if (t0 === true) t0 = t;
if (t0) t -= t0;
} else {
t = frame++;
}
gen.write(t);
requestAnimationFrame(update);
};
requestAnimationFrame(update);
return gen;
};
export {
raf
};