JavaScript/TypeScript library to run repetitive tasks with throttle control and other cool features

Overview

Repeatify

JavaScript/TypeScript library to run repetitive tasks with throttle control and other cool features

image

Install

npm install repeatify

Usage

import { throttle } from 'repeatify';

function timeConsuming() {
 return new Promise((resolve) => {
  setTimeout(() => {
   resolve({ data: { datetime: Date.now() } });
  }, 200);
 });
}

const options = { intervalLimit: 1000, repeat: 10 };

await throttle(timeConsuming, options, {
 update: (status) => {},
 complete: (result) => {},
 error: (error) => {},
});

API

throttle(task, options, callbacks?)

Execute a promise a certain number of times with a fixed iteration interval.

task

Type: promise

Promise that will be executed

function timeConsuming(context) {
 return new Promise((resolve) => {
  setTimeout(() => {
   resolve({ data: { datetime: Date.now() } });
  }, 200);
 });
}

The context argument provides contextual data of the running task.

currentIteration

current iteration counter

options

a copy of the original options object

returning object

The data object in the returning object may contain any information to be received in the update event callback. Example:

{ data: { datetime: Date.now() }

Add abort in the returning object to exit the process at the current cycle. Example:

{ abort: true, data: { datetime: Date.now() }

options

Type: object

Options object to set execution parameters

{  repeat: 10, intervalLimit: 1000}

repeat

The number of times to execute the given promise

intervalLimit

Sets the minimum interval for the execution

callbacks

Type: object

Callbacks to handle events

{
 update: (status) => {},
 complete: (result) => {},
 error: (error) => {},
}

update (callback)

Triggered at the end of every cycle. Provides an object with data related to the running task.

status object

{
  currentIteration: 1,
  elapsedTime: 203,
  finalElapsedTime: 1000,
  throttleApplied: 797,
  taskResult: { data: { datetime: 1642197014924 } }
}

complete (callback)

Triggered when execution has finished. It provides an object with result data.

result object

{
  exitMode: 0,
  totalElapsedTime: 10171,
  options: { intervalLimit: 1000, repeat: 10 }
}

exitMode: Indicates how the execution ended; 0 = Normal (at last cycle), 1 = Abort (as per request).

totalElapsedTime: The final duration time of the execution.

options: This object is a copy of the original options object passed as argument.

error (callback)

This callback method gets triggered if there is an error on the task execution.

You might also like...

Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Linux Remote This is a web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control. Do

Jul 6, 2022

Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services.

Tidbyt Client for Node.js Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services. Insta

Dec 17, 2022

Tool Cool Color Picker is a color picker library written in typescript and using web component technologies.

Tool Cool Color Picker is a color picker library written in typescript and using web component technologies.

Tool Cool Color Picker Tool Cool Color Picker is a color picker library written in typescript and using web component technologies. Check out the demo

Oct 23, 2022

Run a command, watch the filesystem, stop the process on file change and then run the command again...

hubmon Run a command, watch the filesystem, stop the process on file change and then run the command again... Install You can install this command lin

Jul 30, 2022

A javascript based whatsapp bot for downloading and sending media from youtube and facebook in different formats alongwith couple of other features.

Whatsmazan Available Features Downlaod youtube mp4 Video and send Downlaod youtube mp3 audio and send Search something from youtube Downlaod facebook

Oct 30, 2022

A to-do list app is a productivity tool designed to help users to create and maintain lists of tasks that they need to complete and it allows user to edit their tasks even after the task is saved. Built with CSS, HTML, and JAVASCRIPT.

Tumaini Maganiko πŸ“— Table of Contents πŸ“— Table of Contents πŸ“– To Do List PROJECT πŸ›  Built With Tech Stack Key Features πŸš€ Live Demo πŸ’» Getting Started

May 9, 2023

A simple to-do app for managing daily tasks built with Webpack, JavaScript, HTML, and CSS with the functionality to manipulate multiple completed tasks and store them to local storage.

A simple to-do app for managing daily tasks built with Webpack, JavaScript, HTML, and CSS with the functionality to manipulate multiple completed tasks and store them to local storage.

TODO LIST APP In this project, I have built a simple HTML list of To Do tasks. The list is styled according to the listed specifications . This simple

Jun 7, 2022

A Todo list app that allows the user to add tasks, delete, edit, chage, and clear all completed tasks. Built with JavaScript, CSS and Html.

To Do list: interactive list description: A todo list app that allow users to add new task, delete, edit, and clear all completed.Built with JavaScrip

Aug 4, 2022
Releases(v1.0.0)
Owner
Evert Arias
Full-Stack Developer - Javascript, Vue.js, Node.js. Focused on Android apps, CLI tools, and npm packages.
Evert Arias
This is a To-Do List. It shows a minimalist design with the next features: Add new tasks, edit tasks, markup completed tasks, and erase all completed tasks. Built with JavaScript.

Project Name To Do List Built With HTML CSS JavaScript Live Demo To do List Live Demo Link Getting Started This is a To Do List. It shows a minimalist

Santiago CΓ‘rdenas 6 Jun 9, 2022
A simple JS To Do List bundled using Webpack. You can add new tasks, edit existing tasks, check completed tasks, and delete tasks from the list. It is built mainly with Javascript.

To-Do-List A simple HTML list of To Do built using webpack and served by a webpack dev server. Live Link See Demo Built With HTML, CSS, Javascript To

Michael Ugochukwu 3 May 10, 2022
To Do list is a small but useful project to make list app , you can add tasks delete tasks and modify tasks, the project built using HTML, CSS, JavaScript

Project Name The To-Do-List app description this is a project in the second week of the second module in microverse. its a useful to do list that save

Alzubair Alqaraghuli 5 Jul 25, 2022
A simple to do list app built with HTML, CSS and JavaScript. Users can add daily tasks, edit the tasks, delete the tasks when it's done

To Do List This is a website that allows users to manage the tasks. users can add every task to do and when the task is done users can delete the task

Mustafa Fahimy 8 Jul 21, 2022
Grayce Muthui 8 Jun 16, 2022
A to do list where you can add tasks, mark completed tasks and clear all completed tasks.

To Do List A to do list where you can add tasks, mark completed tasks and clear all completed tasks. You can rearrange the order of the tasks by doubl

Amira 7 Mar 4, 2022
A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

Web Control for ZJU Fast-Drone-250 A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control (tested on Xiaomi

null 6 Nov 11, 2022