What is scheduler?
The scheduler package is a lightweight coordination module that allows for scheduling work with different priorities. It is used by React internally for its own scheduling of updates, and it can be used in other contexts to manage tasks with various levels of urgency.
What are scheduler's main functionalities?
Immediate Priority Scheduling
Schedules a task to be performed with the highest priority, effectively running it as soon as possible.
import { unstable_scheduleCallback, unstable_ImmediatePriority } from 'scheduler';
unstable_scheduleCallback(unstable_ImmediatePriority, () => {
console.log('Run this task immediately');
});
User Blocking Priority Scheduling
Schedules a task with a priority level that is high but not as immediate, suitable for tasks that must respond to user input, like input handlers.
import { unstable_scheduleCallback, unstable_UserBlockingPriority } from 'scheduler';
unstable_scheduleCallback(unstable_UserBlockingPriority, () => {
console.log('Run this task with user-blocking priority');
});
Normal Priority Scheduling
Schedules a task with a normal priority, which is suitable for tasks that do not need to be run immediately or in response to direct user input.
import { unstable_scheduleCallback, unstable_NormalPriority } from 'scheduler';
unstable_scheduleCallback(unstable_NormalPriority, () => {
console.log('Run this task with normal priority');
});
Idle Priority Scheduling
Schedules a task with the lowest priority, which will run when the browser is idle, suitable for background and low priority tasks.
import { unstable_scheduleCallback, unstable_IdlePriority } from 'scheduler';
unstable_scheduleCallback(unstable_IdlePriority, () => {
console.log('Run this task when the browser is idle');
});
Other packages similar to scheduler
node-schedule
A cron-like and not-cron-like job scheduler for Node.js. It allows scheduling using cron syntax as well as more flexible date-based scheduling, unlike the scheduler package which is more about prioritizing task execution.
agenda
A light and flexible job scheduling library for Node.js that uses MongoDB for persisting job data. It's more feature-rich for job scheduling with persistence, compared to the in-memory scheduling approach of the scheduler package.
bull
A Redis-based queue system for handling distributed jobs and messages in Node.js. It's more suitable for distributed systems and offers features like rate limiting, which are not present in the scheduler package.
later
A library for describing recurring schedules and calculating their occurrences. It provides a more human-readable way of scheduling tasks, unlike the scheduler package which focuses on task prioritization rather than recurrence patterns.
Scheduler
Simpler library for managing CronJobs.
Each job can be identified by id.
##TODO:
- job should be run using web workers if needed.
- every job should has unique id.
Versions
Works with node 0.4
License
(The MIT License)
Copyright (c) 2011 Anton Podviaznikov podviaznikov@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.