Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

worker-timer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-timer - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

16

index.js
"use strict";
if (!(global === global.window && global.URL && global.Blob && global.Worker)) {
module.exports = global;
} else {
if (global === global.window && global.URL && global.Blob && global.Worker) {
module.exports = (function() {

@@ -32,3 +30,3 @@ var TIMER_WORKER_SOURCE = [

if (_callbacks[e.data]) {
_callbacks[e.data]();
_callbacks[e.data].callback.apply(null, _callbacks[e.data].params);
}

@@ -39,6 +37,8 @@ };

setInterval: function(callback, delay) {
var params = Array.prototype.slice.call(arguments, 2);
_timerId += 1;
_timer.postMessage({ type: "setInterval", timerId: _timerId, delay: delay });
_callbacks[_timerId] = callback;
_callbacks[_timerId] = { callback: callback, params: params };

@@ -48,6 +48,8 @@ return _timerId;

setTimeout: function(callback, delay) {
var params = Array.prototype.slice.call(arguments, 2);
_timerId += 1;
_timer.postMessage({ type: "setTimeout", timerId: _timerId, delay: delay });
_callbacks[_timerId] = callback;
_callbacks[_timerId] = { callback: callback, params: params };

@@ -66,2 +68,4 @@ return _timerId;

})();
} else {
module.exports = global;
}
{
"name": "worker-timer",
"description": "Stable timer API",
"version": "0.1.1",
"description": "Timer API that works stable in background tabs",
"version": "1.0.0",
"author": "mohayonao <mohayonao@gmail.com>",

@@ -10,14 +10,21 @@ "bugs": {

"devDependencies": {
"browserify": "^8.1.1",
"mocha-phantomjs": "^3.5.3",
"phantomjs": "^1.9.13",
"uglify-js": "^2.4.16"
"karma": "^0.12.37",
"karma-browserify": "^4.4.2",
"karma-chrome-launcher": "^0.1.12",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.1.10",
"mocha": "^2.3.4"
},
"files": [
"package.json",
"index.js",
"README.md"
],
"homepage": "https://github.com/mohayonao/worker-timer/",
"keywords": [
"timer",
"clearInterval",
"clearTimeout",
"setInterval",
"setTimeout",
"clearInterval",
"clearTimeout",
"timer",
"webworker"

@@ -32,7 +39,4 @@ ],

"scripts": {
"build": "npm run build-browser && npm run build-minify",
"build-browser": "browserify index.js --standalone WorkerTimer > build/worker-timer.js",
"build-minify": "uglifyjs build/worker-timer.js > build/worker-timer.min.js",
"test": "mocha-phantomjs index.html"
"test": "karma start"
}
}
# worker-timer
[![Build Status](http://img.shields.io/travis/mohayonao/worker-timer.svg?style=flat-square)](https://travis-ci.org/mohayonao/worker-timer)
[![NPM Version](http://img.shields.io/npm/v/worker-timer.svg?style=flat-square)](https://www.npmjs.org/package/worker-timer)
[![Bower](https://img.shields.io/bower/v/worker-timer.svg?style=flat-square)](https://github.com/mohayonao/worker-timer)
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://mohayonao.mit-license.org/)
> Stable timer API
> Timer API that works stable in background tabs
## Installation
bower:
```
bower install worker-timer
npm install worker-timer
```
downloads:
- [worker-timer.js](https://raw.githubusercontent.com/mohayonao/tickable-timer/master/build/worker-timer.js)
- [worker-timer.min.js](https://raw.githubusercontent.com/mohayonao/tickable-timer/master/build/worker-timer.min.js)
## API
- `setInterval(callback: function, delay: number): number`
- `setInterval(callback: function, delay: number, ...params: any): number`
- `clearInterval(timerId: number): void`
- `setTimeout(callback: function, delay: number): number`
- `setTimeout(callback: function, delay: number, ...params: any): number`
- `clearTimeout(timerId: number): void`
## Example
Same as the native Timer API
```js
const WorkerTimer = require("worker-timer");
let count = 0;
WorkerTimer.setInterval(() => {
count += 1;
console.log("count: " + count);
}, 1000);
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc