-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Labels
Description
Kicking off the idea/convo of including an API within Backburner for optimally batching work within a rAF scheduler for reads/writes. Addons obviously exist to leverage this, however it's so fundamental and a pattern we should be promoting "out-of-box" with an explicit API for doing both. Thoughts @krisselden @rwjblue @stefanpenner
_reads: [],
_writes: [],
_running: false,
scheduleRead(callback) {
this._reads.unshift(callback);
this._run();
},
scheduleWrite(callback) {
this._writes.unshift(callback);
this._run();
},
_run() {
if (!this._running) {
this._running = true;
rAF(() => {
join(() => {
for (let i = 0, rlen = this._reads.length; i < rlen; i++) {
this._reads.pop()();
}
for (let i = 0, wlen = this._writes.length; i < wlen; i++) {
this._writes.pop()();
}
this._running = false;
if (this._writes.length > 0 || this._reads.length > 0) {
this._run();
}
});
});
}
}