Skip to content

post-task 1.2.0

Install from the command line:
Learn more about npm packages
$ npm install @adevinta/post-task@1.2.0
Install via package.json:
"@adevinta/post-task": "1.2.0"

About this version

@adevinta/post-task

A pre-configured progressively-enhancement utility function based on the Scheduler API.

If the Scheduler API is available, use it. Otherwise set a timeout as a fallback.

The Scheduler API relies on browser heuristics, while the fallback waits and calls back only after a certain time has passed.

The tasks all return a Promise<void> since the scheduler.postTask returns one.

The interface re-exposes the values accepted for the scheduler.postTask API and forwards them through when that API is available.

The fallbacks are configured as following:

Priority Timeout delay (ms)
"user-blocking" 0
"user-visible" 0
"background" 150

There is one exception: if a priority of "user-blocking" is passed, and the Scheduler API is not available, the fallback will be queueMicrotask if that function is available, which it usually will be, including in Node.js.

This function is useful for breaking up chunks of work and allowing the event loop to cycle, which is particularly important when focusing on the Interaction to Next Paint web vital and of course the smooth interaction which it tries to measure.

Use

import postTask from "@adevinta/post-task";

// ...
postTask(() => {
  trackEvent("something-happened");
}, "background");

Formats

This package is equally available as ESM and CJS and has a single, default export.

Details


Assets

  • post-task-1.2.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all