Socket
Socket
Sign inDemoInstall

@maverick-js/scheduler

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @maverick-js/scheduler

A tiny (~250B) microtask scheduler.


Version published
Maintainers
1
Install size
5.44 kB
Created

Readme

Source

Scheduler

package-badge license-badge size-badge

This is a tiny (~250B minzipped) scheduler which batches and runs tasks off the microtask queue.

Installation

$: npm i @maverick-js/scheduler

$: pnpm i @maverick-js/scheduler

$: yarn add @maverick-js/scheduler

Usage

import { createScheduler } from '@maverick-js/scheduler';

const scheduler = createScheduler();

const taskA = () => {};
const taskB = () => {};

// Queue tasks.
scheduler.enqueue(taskA);
scheduler.enqueue(taskB);

// Be notified of a flush.
const stop = scheduler.onFlush(() => {
  console.log('Flushed!');
});

stop(); // unsubscribe

// Schedule a flush - can be invoked more than once.
scheduler.flush();

// Wait for flush to complete.
await scheduler.tick;

// Synchronously flush the queue whenever desired.
scheduler.flushSync();

Extra reading:

  • The source file is only ~80 LOC so feel free to dig through.
  • You can read more about microtasks on MDN.

Inspiration

@maverick-js/scheduler was made possible based on my learnings from:

FAQs

Last updated on 20 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc