This repository has been archived by the owner on Jun 9, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.WorkerTimer = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
(function (global){ | ||
"use strict"; | ||
|
||
if (global === global.window && global.URL && global.Blob && global.Worker) { | ||
module.exports = (function() { | ||
var TIMER_WORKER_SOURCE = [ | ||
"var timerIds = {}, _ = {};", | ||
"_.setInterval = function(args) {", | ||
" timerIds[args.timerId] = setInterval(function() { postMessage(args.timerId); }, args.delay);", | ||
"};", | ||
"_.clearInterval = function(args) {", | ||
" clearInterval(timerIds[args.timerId]);", | ||
"};", | ||
"_.setTimeout = function(args) {", | ||
" timerIds[args.timerId] = setTimeout(function() { postMessage(args.timerId); }, args.delay);", | ||
"};", | ||
"_.clearTimeout = function(args) {", | ||
" clearTimeout(timerIds[args.timerId]);", | ||
"};", | ||
"onmessage = function(e) { _[e.data.type](e.data) };" | ||
].join(""); | ||
|
||
var _timerId = 0; | ||
var _callbacks = {}; | ||
var _timer = new global.Worker(global.URL.createObjectURL( | ||
new global.Blob([ TIMER_WORKER_SOURCE ], { type: "text/javascript" }) | ||
)); | ||
|
||
_timer.onmessage = function(e) { | ||
if (_callbacks[e.data]) { | ||
_callbacks[e.data].callback.apply(null, _callbacks[e.data].params); | ||
} | ||
}; | ||
|
||
return { | ||
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: callback, params: params }; | ||
|
||
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: callback, params: params }; | ||
|
||
return _timerId; | ||
}, | ||
clearInterval: function(timerId) { | ||
_timer.postMessage({ type: "clearInterval", timerId: timerId }); | ||
_callbacks[timerId] = null; | ||
}, | ||
clearTimeout: function(timerId) { | ||
_timer.postMessage({ type: "clearTimeout", timerId: timerId }); | ||
_callbacks[timerId] = null; | ||
} | ||
}; | ||
})(); | ||
} else { | ||
module.exports = global; | ||
} | ||
|
||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{}]},{},[1])(1) | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters