Socket
Socket
Sign inDemoInstall

backburner.js

Package Overview
Dependencies
0
Maintainers
7
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    backburner.js

Backburner.js is a simple run loop-esque library for coalescing actions


Version published
Weekly downloads
27K
decreased by-4.72%
Maintainers
7
Install size
1.11 MB
Created
Weekly downloads
 

Changelog

Source

v2.8.0 (2023-11-17)

:bug: Bug Fix
  • #402 Ensure scheduleOnce works correctly following a cancelled job (@davidtaylorhq)
Committers: 1

Readme

Source

backburner.js Build Status

A rewrite of the Ember.js run loop as a generic microlibrary.

TL;DR

A priority queue that will efficiently batch, order, reorder and process work; done via scheduling work on specific queues.

API

Constructor

ConstructorDescription
new Backburner()instantiate a Backburner instance with an array of queue names

Instance methods

MethodDescription
Backburner#runexecute the passed function and flush any deferred actions
Backburner#deferdefer the passed function to run inside the specified queue
Backburner#deferOncedefer the passed function to run inside the specified queue, only execute it once
Backburner#setTimeoutexecute the passed function in a specified amount of time
Backburner#debounceexecute the passed function in a specified amount of time, reset timer upon additional calls
Backburner#throttlerate-limit the passed function for a specified amount of time
Backburner#cancelcancel a deferOnce, setTimeout, debounce or throttle
Backburner#onAdd an event callback. Supports the following events:
  • begin - Fires whenever the runloop begins. Callbacks are passed the current instance and the previous instance.
  • end - Fires whenever the runloop ends. Callbacks are passed the current instance and the next instance.
Backburner#offRemoves an event callback
Backburner#joinJoin the passed method with an existing queue and execute immediately, if there isn't one use Backburner#run
Backburner#getDebugInfoReturns debug information for counters, timers and queues, which includes surfacing the stack trace information for the respective calls
Alias
AliasDescription
Backburner#schedulesame as defer
Backburner#scheduleOncesame as deferOnce
Backburner#latersame as setTimeout

Example usage

The following code will only cause a single DOM manipulation:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Backburner demo</title>
  </head>

  <body>
    <div id="name"></div>

    <script type="module">
      import Backburner from './dist/es6/backburner.js'

      var backburner = new Backburner(['render']),
        person = {name: 'Erik'};

      function updateName() {
        document.querySelector('#name').innerHTML = person.name;
      }

      function setName(name) {
        person.name = name;
        backburner.deferOnce('render', updateName);
      }

      backburner.run(function() {
        setName('Kris');
        setName('Tom');
        setName('Yehuda');
      });
    </script>
  </body>
</html>

FAQs

Last updated on 17 Nov 2023

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