Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

task-invoker

an-parubets2ISC1.1.0TypeScript support: included

Zero delay task scheduler

task invoker, task scheduler, scheduler, js scheduler

readme

task-invoker

A tiny TypeScript/JavaScript utility for scheduling asynchronous task execution with zero delay. Perfect for deferring function calls to the event loop without using setTimeout(fn, 0).

npm version
npm downloads
semantic release
license


✨ Features

  • 🌀 Run tasks asynchronously with zero delay
  • ⚡ Lightweight and dependency-free
  • 🛡️ Written in TypeScript with type definitions

📦 Installation

npm install task-invoker
# or
yarn add task-invoker
# or
pnpm add task-invoker

🚀 Usage

import { schedule } from 'task-invoker';

const foo = () => {
  console.log('Hello from async task!');
};

// Task will be executed asynchronously, with no artificial delay
schedule(foo);

console.log('This will log first.');

🛠️ How it Works

task-invoker leverages microtask or macrotask scheduling to queue your function for execution after the current call stack clears — without introducing unnecessary delays.

This means:

  • No need for setTimeout(fn, 0)
  • Works consistently across modern runtimes
  • Ensures smoother async flows

📚 API

schedule(fn: (...args: any[]) => void): void

Schedules a function to run asynchronously.

  • fn — function to execute

📖 Examples

Debouncing heavy tasks

import { schedule } from 'task-invoker';

window.addEventListener('resize', () => {
  schedule(() => {
    console.log('Window resized, handle expensive logic here');
  });
});

Async UI updates

schedule(() => {
  document.body.classList.add('loaded');
});


📜 License

MIT © Anatolii Parubets

changelog

1.1.0 (2025-10-10)

Features

1.0.3 (2024-09-23)

Bug Fixes

1.0.2 (2023-03-10)

Bug Fixes

1.0.1 (2023-03-10)

Bug Fixes

1.0.0 (2023-03-10)

Bug Fixes

Features

  • add semantic release (2ffba03)
  • add zero delay task scheduler (43860b6)
  • add zero delay task scheduler (1421e55)