# ptic

> precise resyncing interval

Latest version **1.0.0** (published 2014-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ptic
pnpm add ptic
yarn add ptic
bun add ptic
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-10-02 |
| First published | 2013-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Manuel Ernst |
| Maintainers | zaphod1984 |
| Keywords | interval, tick, precise, resync |

## Links

- npm: https://www.npmjs.com/package/ptic
- Repository: https://github.com/zaphod1984/node-ptic
- Issues: https://github.com/zaphod1984/node-ptic/issues
- npm.io page: https://npm.io/package/ptic

## Recent versions

- 1.0.0 (latest) — 2014-10-02
- 0.3.1 — 2014-01-13
- 0.3.0 — 2013-11-17
- 0.2.2 — 2013-11-15
- 0.2.0 — 2013-11-11
- 0.1.2 — 2013-11-05
- 0.1.1 — 2013-11-05
- 0.1.0 — 2013-11-02
- 0.0.3 — 2013-11-01
- 0.0.2 — 2013-11-01
- 0.0.1 — 2013-11-01

## README

# Precise TICker [![Build Status](https://travis-ci.org/zaphod1984/node-ptic.png)](https://travis-ci.org/zaphod1984/node-ptic)

[![NPM](https://nodei.co/npm/ptic.png)](https://nodei.co/npm/ptic/)

[![NPM](https://nodei.co/npm-dl/ptic.png?months=3)](https://nodei.co/npm/ptic/)

PTic is a more precise interval emitter. It resyncs itselfs to the desired timeframe. Bind to the `tick` event to get notified depending on the interval.

Check the ticker example in the example section for a comparism of setInterval and PTic.

## Installation

````
npm install ptic
````

## Run Tests

````
npm tests
````

## Usage

### Constructor([interval, [autoStart]])

creates a ticker object that emits a `tick` event according to the specified interval.
parameters:

* `interval`: the time in milliseconds between two ticks, default: 1000ms.    
* `autoStart`: optional flag that specifies if the ticker should start on instantiation, default: false

### ptic.start([startImmediately])
causes the ticker to start emitting `tick` events

* `startImmediately`: specifies if the ticker should start immedately. if set to false the ticker first ticks on the next step in the interval raster.

### ptic.stop()
stops the ticker

### ptic.isRunning()
indicates if the ticker is currently emitting tick events.

## Behaviour
````
T: emitted tick

interval: 10ms, startImmediately=true

0         10        20        30        40
|---------|---------|---------|---------|
   ^
   start(true)
   T      T         T         T         T


interval: 10ms, startImmediately=false

0         10        20        30        40
|---------|---------|---------|---------|
   ^
   start(false)
          T         T         T         T
````

## Example
````javascript

var PTic = require('ptic');

var ticker = new PTic(1000, true);

ticker.on('tick', function() {
    console.log('tick');
});

ticker.start();

setTimeout(function() {
    ticker.stop();
}, 4000);

//output:
//tick
//tick
//tick
//tick
//tick

````

---
_Source: https://npm.io/package/ptic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
