Socket
Socket
Sign inDemoInstall

@repeaterjs/timers

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @repeaterjs/timers

Async iterator timer functions


Version published
Weekly downloads
218
decreased by-4.39%
Maintainers
1
Install size
131 kB
Created
Weekly downloads
 

Changelog

Source

limiters@0.3.3 - 2019-10-13

Fixed

  • build files with target set to es5 rather than esnext

Readme

Source

@repeaterjs/timers

This package is experimental!

Cancelable timers, implemented with repeaters

For more information, visit repeater.js.org.

function delay(wait: number): Repeater<number>;

delay returns a repeater which yields Date.now() wait milliseconds after next is called. Each call to next runs an independent timer. All outstanding timers can be canceled by calling return.

function timeout(wait: number): Repeater<undefined>;

timeout returns a repeater which rejects with a TimeoutError if the repeater does not receive another call to next or return after the specified wait. This behavior is useful when you want to place a fixed upper bound on how long each iteration of an async iterator can take with Repeater.race.

import { Repeater } from "@repeaterjs/repeater";
import { timeout } from "@repeaterjs/timers";

const repeater = new Repeater(async (push) => {
  await push(1);
  await push(2);
  await new Promise((resolve) => setTimeout(resolve, 2000));
  await push(3);
});

try {
  (async () => {
    for await (const num of Repeater.race([repeater, timeout(1000)])) {
      console.log(num); // 1, 2
    }
  })();
} catch (err) {
  console.log(err); // TimeoutError: 1000 ms elapsed
}
function interval(wait: number, buffer?: RepeaterBuffer<number>): Repeater<number>;

interval returns a repeater which resolves with the current timestamp every wait milliseconds. The timer does not start until you call next on the returned iterator, and can be canceled by calling return.

FAQs

Last updated on 10 Nov 2019

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