https://github.com/localvoid/dom_scheduler
DOM Scheduler for read/write tasks.
https://github.com/localvoid/dom_scheduler
Last synced: about 1 month ago
JSON representation
DOM Scheduler for read/write tasks.
- Host: GitHub
- URL: https://github.com/localvoid/dom_scheduler
- Owner: localvoid
- License: bsd-2-clause
- Created: 2014-11-24T11:49:30.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-09T11:57:22.000Z (over 11 years ago)
- Last Synced: 2025-06-13T22:42:18.339Z (12 months ago)
- Language: Dart
- Size: 172 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DOM Scheduler for read/write tasks
## API
### Scheduler
The scheduler algorithm is quite simple and looks like this:
```dart
while (writeTasks.isNotEmpty) {
while (writeTasks.isNotEmpty) {
writeTasks.removeFirst().start();
runMicrotasks();
}
while (readTasks.isNotEmpty) {
readTasks.removeFirst().start();
runMicrotasks();
}
}
while (afterTasks.isNotEmpty) {
afterTasks.removeFirst().start();
runMicrotasks();
}
```
It will perform write and read tasks in batches until there are no
write or read tasks left.
Write tasks sorted by their priority, and the tasks with the lowest
value in the priority property are executed first. It is implemented
this way because most of the time tasks priority will be its depth in
the DOM.
Scheduler runs in its own `Zone` and intercepts all microtasks, this
way it is possible to use `Future`s to track dependencies between
tasks.
#### `Frame get nextFrame`
Returns `Frame` that contains tasks for the next animation frame.
#### `Frame get currentFrame`
Returns `Frame` that contains tasks for the current animation frame.
#### `Zone get zone`
Returns Scheduler `Zone`.
### Frame
#### `Future write([int priority = maxPriority])`
Returns `Future` that will be completed when Scheduler starts
executing write tasks with this priority.
#### `Future read()`
Returns `Future` that will be completed when Scheduler starts
executing read tasks.
#### `Future after()`
Returns `Future` that will be completed when Scheduler finishes
executing all write and read tasks.
## Notes
If you are planning to use something else for the write priority and
not depth of the node in the DOM tree, please let me know. Right now
it is implemented in a way that is better suited for depth, and will
behave badly for sparse values.