@nexim/task-scheduler
v1.0.6
Published
A TypeScript task scheduler with persistence and conditional execution.
Downloads
661
Maintainers
Readme
@nexim/task-scheduler
Overview
@nexim/task-scheduler provides a TypeScript task scheduler with persistence and conditional execution. It allows you to schedule recurring tasks with localStorage persistence, conditional execution, and duration-based intervals.
Installation
Install the package using npm or yarn:
npm install @nexim/task-scheduler
# Or using yarn
yarn add @nexim/task-schedulerUsage
import { taskScheduler } from '@nexim/task-scheduler';
// Add a task that runs every 5 minutes
taskScheduler.addTask(
'data-sync',
async () => {
console.log('Syncing data...');
// Your task logic here
},
'5m',
{
shouldRun: () => navigator.onLine, // Only run when online
},
);
// Update last run timestamp
taskScheduler.updateLastRun('data-sync');
// Remove a task
taskScheduler.removeTask('data-sync');Features
- Duration-based intervals: Use human-readable durations like '5m', '1h', '2d'
- Persistence: Task states are persisted in localStorage
- Conditional execution: Optional conditions to check before running tasks
- Error handling: Graceful error handling with logging
- TypeScript support: Full TypeScript support with type safety
Documentation
Read full documentation here.
