Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@maverick-js/scheduler

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maverick-js/scheduler

A tiny (~250B) microtask scheduler.

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 20 Oct 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc