Giter Club home page Giter Club logo

ticle's Introduction

Ticle

A small library that extends the capabilities of the standard setTimeout and setInterval.

Capabilities

  • Setting timers in web worker thread. Some browsers lower the priority of timers, when switching to another tab or minimizing the window, this produce execution delay more than expected. For timers working in a separate thread, there is no such problem.

  • Counting the time difference between set timer and trigger callback

Install

  $ npm install ticle

or

  <script src="https://unpkg.com/ticle@latest/build/ticle.js">

How to use

Timers in worker thread

  import Ticle from 'ticle';
  
  const WorkerTimer = new Ticle.WorkerTimer({ recordDiff: true });
  
  WorkerTimer.setTrustyInterval(
      (diff, arg1) => console.log(diff, arg1),
      1000, 'arg1');
  
  // 1001, arg1
  // ...

Standard

  import Ticle from 'ticle';
  
  const WorkerTimer = new Ticle.SimpleTimer({ recordDiff: true });
  
  WorkerTimer.setInterval(
      (diff, arg1) => console.log(diff, arg1),
      1000, arg1');

Some examples stored in examples/.

Timers constructors

  • WorkerTimer(options)
  • SimpleTimer(options)

Methods

  • setTimeout(func: Function, delay: number [, ...args]) - similar to setTimeout, ...args - any number of arguments provided to func.

  • setInterval(func: Function, delay: number [, ...args]) - similar to setInterval.

  • setTrustyInterval(func: Function, delay: number [, ...args]) - similar to setInterval, realisation base on setTimeout.

  • clearTimeout(id: number) - similar to learTimeout.

  • clearInterval(id: number) - similar to clearInterval.

  • clearTrustyInterval(id: number) - similar to clearTimeout, but for setTrustyInterval.

Options

  • recordDiff: boolean - whether to record time difference between set timer and trigger callback. The result is passed as the 1st argument to the callback.

ticle's People

Contributors

hokid avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.