Initial project import
This commit is contained in:
202
node_modules/promise-worker-transferable/LICENSE
generated
vendored
Normal file
202
node_modules/promise-worker-transferable/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
294
node_modules/promise-worker-transferable/README.md
generated
vendored
Normal file
294
node_modules/promise-worker-transferable/README.md
generated
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
promise-worker-transferable [](https://travis-ci.org/terikon/promise-worker-transferable)
|
||||
====
|
||||
|
||||
Modified version of [promise-worker](https://github.com/nolanlawson/promise-worker) library that supports object transferring. Possibly works slower than original for not transferable messages.
|
||||
|
||||
As mentioned [here](https://github.com/nolanlawson/promise-worker/issues/13), promise-worker library will not get support for blobs and transferables. So here promise-worker-transferable goes.
|
||||
|
||||
**Goals:**
|
||||
|
||||
* Tiny footprint (~2.5kB min+gz)
|
||||
* Assumes you have a separate `worker.js` file (easier to debug, better browser support)
|
||||
* Removed from promise-worker and no longer true: `JSON.stringify`s messages [for performance](http://nolanlawson.com/2016/02/29/high-performance-web-worker-messages/)
|
||||
* Instead, it's now possbile to transfer blobs, as well as attach transferList array to transfer objects, which works much faster for larger objects.
|
||||
|
||||
**Live examples:**
|
||||
|
||||
* [Web Workers](https://bl.ocks.org/nolanlawson/05e74a8408a099635c9a38f839b5ae9f)
|
||||
* [Service Workers](https://bl.ocks.org/nolanlawson/91a7f5809f2e17a2e6a753a3cb8d2eec)
|
||||
|
||||
Usage
|
||||
---
|
||||
|
||||
Install:
|
||||
|
||||
npm install promise-worker-transferable
|
||||
|
||||
Inside your main bundle:
|
||||
|
||||
```js
|
||||
// main.js
|
||||
var PromiseWorker = require('promise-worker-transferable');
|
||||
var worker = new Worker('worker.js');
|
||||
var promiseWorker = new PromiseWorker(worker);
|
||||
|
||||
promiseWorker.postMessage('ping').then(function (response) {
|
||||
// handle response
|
||||
}).catch(function (error) {
|
||||
// handle error
|
||||
});
|
||||
|
||||
// With transferList
|
||||
promiseWorker.postMessage(pingImageData, [pingImageData.data.buffer]) // pongImageData transferred from main to worker
|
||||
.then(function (response) {
|
||||
// handle response
|
||||
}).catch(function (error) {
|
||||
// handle error
|
||||
});
|
||||
```
|
||||
|
||||
Inside your `worker.js` bundle:
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
var registerPromiseWorker = require('promise-worker-transferable/register');
|
||||
|
||||
registerPromiseWorker(function (message) {
|
||||
return 'pong';
|
||||
});
|
||||
|
||||
// With transferList
|
||||
registerPromiseWorker(function (message, withTransferList) {
|
||||
return withTransferList(pongImageData, [pongImageData.data.buffer]); // pongImageData transferred from worker to main
|
||||
});
|
||||
```
|
||||
|
||||
Note that you `require()` two separate APIs, so the library is split
|
||||
between the `worker.js` and main file. This keeps the total bundle size smaller.
|
||||
|
||||
|
||||
### Message format
|
||||
|
||||
The message you send can be any object, array, string, number, etc.:
|
||||
|
||||
```js
|
||||
// main.js
|
||||
promiseWorker.postMessage({
|
||||
hello: 'world',
|
||||
answer: 42,
|
||||
"this is fun": true
|
||||
}).then(/* ... */);
|
||||
```
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
registerPromiseWorker(function (message) {
|
||||
console.log(message); // { hello: 'world', answer: 42, 'this is fun': true }
|
||||
});
|
||||
```
|
||||
|
||||
### Promises
|
||||
|
||||
Inside of the worker, the registered handler can return either a Promise or a normal value:
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
registerPromiseWorker(function () {
|
||||
return Promise.resolve().then(function () {
|
||||
return 'much async, very promise';
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// main.js
|
||||
promiseWorker.postMessage(null).then(function (message) {
|
||||
console.log(message): // 'much async, very promise'
|
||||
});
|
||||
```
|
||||
|
||||
Promise can return withTransferList as well:
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
registerPromiseWorker(function (_, withTransferList) {
|
||||
return Promise.resolve().then(function () {
|
||||
return withTransferList(pongImageData, [pongImageData.data.buffer]); // pongImageData transferred to webworker
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// main.js
|
||||
promiseWorker.postMessage(null).then(function (message) {
|
||||
// message contains pongImageData
|
||||
});
|
||||
```
|
||||
|
||||
### Error handling
|
||||
|
||||
Any thrown errors or asynchronous rejections from the worker will
|
||||
be propagated to the main thread as a rejected Promise. For instance:
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
registerPromiseWorker(function (message) {
|
||||
throw new Error('naughty!');
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// main.js
|
||||
promiseWorker.postMessage('whoops').catch(function (err) {
|
||||
console.log(err.message); // 'naughty!'
|
||||
});
|
||||
```
|
||||
|
||||
Note that stacktraces cannot be sent from the worker to the main thread, so you
|
||||
will have to debug those errors yourself. This library does however, print
|
||||
messages to `console.error()`, so you should see them there.
|
||||
|
||||
### Multi-type messages
|
||||
|
||||
If you need to send messages of multiple types to the worker, just add
|
||||
some type information to the message you send:
|
||||
|
||||
```js
|
||||
// main.js
|
||||
promiseWorker.postMessage({
|
||||
type: 'en'
|
||||
}).then(/* ... */);
|
||||
|
||||
promiseWorker.postMessage({
|
||||
type: 'fr'
|
||||
}).then(/* ... */);
|
||||
```
|
||||
|
||||
```js
|
||||
// worker.js
|
||||
registerPromiseWorker(function (message) {
|
||||
if (message.type === 'en') {
|
||||
return 'Hello!';
|
||||
} else if (message.type === 'fr') {
|
||||
return 'Bonjour!';
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Service Workers
|
||||
|
||||
Communicating with a Service Worker is the same as with a Web Worker.
|
||||
However, you have to wait for the Service Worker to install and start controlling the page. Here's an example:
|
||||
|
||||
```js
|
||||
navigator.serviceWorker.register('sw.js', {
|
||||
scope: './'
|
||||
}).then(function () {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// already active and controlling this page
|
||||
return navigator.serviceWorker;
|
||||
}
|
||||
// wait for a new service worker to control this page
|
||||
return new Promise(function (resolve) {
|
||||
function onControllerChange() {
|
||||
navigator.serviceWorker.removeEventListener('controllerchange', onControllerChange);
|
||||
resolve(navigator.serviceWorker);
|
||||
}
|
||||
navigator.serviceWorker.addEventListener('controllerchange', onControllerChange);
|
||||
});
|
||||
}).then(function (worker) { // the worker is ready
|
||||
var promiseWorker = new PromiseWorker(worker);
|
||||
return promiseWorker.postMessage('hello worker!');
|
||||
}).catch(console.log.bind(console));
|
||||
```
|
||||
|
||||
Then inside your Service Worker:
|
||||
|
||||
```js
|
||||
var registerPromiseWorker = require('../register');
|
||||
|
||||
registerPromiseWorker(function (msg) {
|
||||
return 'hello main thread!';
|
||||
});
|
||||
|
||||
self.addEventListener('activate', function(event) {
|
||||
event.waitUntil(self.clients.claim()); // activate right now
|
||||
});
|
||||
```
|
||||
|
||||
Browser support
|
||||
----
|
||||
|
||||
* Chrome
|
||||
* Firefox
|
||||
* Safari 8+
|
||||
* IE 10+
|
||||
* Edge
|
||||
* iOS 8+
|
||||
* Android 4.4+
|
||||
|
||||
If a browser [doesn't support Web Workers](http://caniuse.com/webworker) but you still want to use this library,
|
||||
then you can use [pseudo-worker](https://github.com/nolanlawson/pseudo-worker).
|
||||
|
||||
For Service Worker support, Chrome 40 and 41 are known to be buggy (see [#9](https://github.com/nolanlawson/promise-worker/pull/9)), but 42+ are supported.
|
||||
|
||||
This library is not designed to run in Node.js.
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
### Main bundle
|
||||
|
||||
#### `new PromiseWorker(worker)`
|
||||
|
||||
Create a new `PromiseWorker`, using the given worker.
|
||||
|
||||
* `worker` - the `Worker` or [PseudoWorker](https://github.com/nolanlawson/pseudo-worker) to use.
|
||||
|
||||
#### `PromiseWorker.postMessage(message, optionalTransferList)`
|
||||
|
||||
Send a message to the worker and return a Promise.
|
||||
|
||||
* `message` - object - required
|
||||
* The message to send.
|
||||
* `optionalTransferList` - array of objects to transfer, just as in usual Worker.postMessage.
|
||||
* returns a Promise
|
||||
|
||||
### Worker bundle
|
||||
|
||||
Register a message handler inside of the worker. Your handler consumes a message
|
||||
and returns a Promise or value.
|
||||
|
||||
#### `registerPromiseWorker(function)`
|
||||
|
||||
* `function`
|
||||
* Takes a message and withTransferList function, returns a Promise or a value.
|
||||
Value can be wrapped with withTransferList. withTransferList gets value and transferList.
|
||||
|
||||
|
||||
Testing the library
|
||||
---
|
||||
|
||||
First:
|
||||
|
||||
npm install
|
||||
|
||||
Then to test in Node (using an XHR/PseudoWorker shim):
|
||||
|
||||
npm test
|
||||
|
||||
Or to test manually in your browser of choice:
|
||||
|
||||
npm run test-local
|
||||
|
||||
Or to test in a browser using SauceLabs:
|
||||
|
||||
npm run test-browser
|
||||
|
||||
Or to test in PhantomJS:
|
||||
|
||||
npm run test-phantom
|
||||
|
||||
Or to test with coverage reports:
|
||||
|
||||
npm run coverage
|
||||
404
node_modules/promise-worker-transferable/dist/promise-worker.js
generated
vendored
Normal file
404
node_modules/promise-worker-transferable/dist/promise-worker.js
generated
vendored
Normal file
@@ -0,0 +1,404 @@
|
||||
(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.PromiseWorker = 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';
|
||||
var Mutation = global.MutationObserver || global.WebKitMutationObserver;
|
||||
|
||||
var scheduleDrain;
|
||||
|
||||
{
|
||||
if (Mutation) {
|
||||
var called = 0;
|
||||
var observer = new Mutation(nextTick);
|
||||
var element = global.document.createTextNode('');
|
||||
observer.observe(element, {
|
||||
characterData: true
|
||||
});
|
||||
scheduleDrain = function () {
|
||||
element.data = (called = ++called % 2);
|
||||
};
|
||||
} else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
|
||||
var channel = new global.MessageChannel();
|
||||
channel.port1.onmessage = nextTick;
|
||||
scheduleDrain = function () {
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
} else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
|
||||
scheduleDrain = function () {
|
||||
|
||||
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
|
||||
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
|
||||
var scriptEl = global.document.createElement('script');
|
||||
scriptEl.onreadystatechange = function () {
|
||||
nextTick();
|
||||
|
||||
scriptEl.onreadystatechange = null;
|
||||
scriptEl.parentNode.removeChild(scriptEl);
|
||||
scriptEl = null;
|
||||
};
|
||||
global.document.documentElement.appendChild(scriptEl);
|
||||
};
|
||||
} else {
|
||||
scheduleDrain = function () {
|
||||
setTimeout(nextTick, 0);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var draining;
|
||||
var queue = [];
|
||||
//named nextTick for less confusing stack traces
|
||||
function nextTick() {
|
||||
draining = true;
|
||||
var i, oldQueue;
|
||||
var len = queue.length;
|
||||
while (len) {
|
||||
oldQueue = queue;
|
||||
queue = [];
|
||||
i = -1;
|
||||
while (++i < len) {
|
||||
oldQueue[i]();
|
||||
}
|
||||
len = queue.length;
|
||||
}
|
||||
draining = false;
|
||||
}
|
||||
|
||||
module.exports = immediate;
|
||||
function immediate(task) {
|
||||
if (queue.push(task) === 1 && !draining) {
|
||||
scheduleDrain();
|
||||
}
|
||||
}
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{}],2:[function(require,module,exports){
|
||||
'use strict';
|
||||
var immediate = require(1);
|
||||
|
||||
/* istanbul ignore next */
|
||||
function INTERNAL() {}
|
||||
|
||||
var handlers = {};
|
||||
|
||||
var REJECTED = ['REJECTED'];
|
||||
var FULFILLED = ['FULFILLED'];
|
||||
var PENDING = ['PENDING'];
|
||||
|
||||
module.exports = Promise;
|
||||
|
||||
function Promise(resolver) {
|
||||
if (typeof resolver !== 'function') {
|
||||
throw new TypeError('resolver must be a function');
|
||||
}
|
||||
this.state = PENDING;
|
||||
this.queue = [];
|
||||
this.outcome = void 0;
|
||||
if (resolver !== INTERNAL) {
|
||||
safelyResolveThenable(this, resolver);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype["catch"] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
||||
Promise.prototype.then = function (onFulfilled, onRejected) {
|
||||
if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||
|
||||
typeof onRejected !== 'function' && this.state === REJECTED) {
|
||||
return this;
|
||||
}
|
||||
var promise = new this.constructor(INTERNAL);
|
||||
if (this.state !== PENDING) {
|
||||
var resolver = this.state === FULFILLED ? onFulfilled : onRejected;
|
||||
unwrap(promise, resolver, this.outcome);
|
||||
} else {
|
||||
this.queue.push(new QueueItem(promise, onFulfilled, onRejected));
|
||||
}
|
||||
|
||||
return promise;
|
||||
};
|
||||
function QueueItem(promise, onFulfilled, onRejected) {
|
||||
this.promise = promise;
|
||||
if (typeof onFulfilled === 'function') {
|
||||
this.onFulfilled = onFulfilled;
|
||||
this.callFulfilled = this.otherCallFulfilled;
|
||||
}
|
||||
if (typeof onRejected === 'function') {
|
||||
this.onRejected = onRejected;
|
||||
this.callRejected = this.otherCallRejected;
|
||||
}
|
||||
}
|
||||
QueueItem.prototype.callFulfilled = function (value) {
|
||||
handlers.resolve(this.promise, value);
|
||||
};
|
||||
QueueItem.prototype.otherCallFulfilled = function (value) {
|
||||
unwrap(this.promise, this.onFulfilled, value);
|
||||
};
|
||||
QueueItem.prototype.callRejected = function (value) {
|
||||
handlers.reject(this.promise, value);
|
||||
};
|
||||
QueueItem.prototype.otherCallRejected = function (value) {
|
||||
unwrap(this.promise, this.onRejected, value);
|
||||
};
|
||||
|
||||
function unwrap(promise, func, value) {
|
||||
immediate(function () {
|
||||
var returnValue;
|
||||
try {
|
||||
returnValue = func(value);
|
||||
} catch (e) {
|
||||
return handlers.reject(promise, e);
|
||||
}
|
||||
if (returnValue === promise) {
|
||||
handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));
|
||||
} else {
|
||||
handlers.resolve(promise, returnValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handlers.resolve = function (self, value) {
|
||||
var result = tryCatch(getThen, value);
|
||||
if (result.status === 'error') {
|
||||
return handlers.reject(self, result.value);
|
||||
}
|
||||
var thenable = result.value;
|
||||
|
||||
if (thenable) {
|
||||
safelyResolveThenable(self, thenable);
|
||||
} else {
|
||||
self.state = FULFILLED;
|
||||
self.outcome = value;
|
||||
var i = -1;
|
||||
var len = self.queue.length;
|
||||
while (++i < len) {
|
||||
self.queue[i].callFulfilled(value);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
};
|
||||
handlers.reject = function (self, error) {
|
||||
self.state = REJECTED;
|
||||
self.outcome = error;
|
||||
var i = -1;
|
||||
var len = self.queue.length;
|
||||
while (++i < len) {
|
||||
self.queue[i].callRejected(error);
|
||||
}
|
||||
return self;
|
||||
};
|
||||
|
||||
function getThen(obj) {
|
||||
// Make sure we only access the accessor once as required by the spec
|
||||
var then = obj && obj.then;
|
||||
if (obj && typeof obj === 'object' && typeof then === 'function') {
|
||||
return function appyThen() {
|
||||
then.apply(obj, arguments);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function safelyResolveThenable(self, thenable) {
|
||||
// Either fulfill, reject or reject with error
|
||||
var called = false;
|
||||
function onError(value) {
|
||||
if (called) {
|
||||
return;
|
||||
}
|
||||
called = true;
|
||||
handlers.reject(self, value);
|
||||
}
|
||||
|
||||
function onSuccess(value) {
|
||||
if (called) {
|
||||
return;
|
||||
}
|
||||
called = true;
|
||||
handlers.resolve(self, value);
|
||||
}
|
||||
|
||||
function tryToUnwrap() {
|
||||
thenable(onSuccess, onError);
|
||||
}
|
||||
|
||||
var result = tryCatch(tryToUnwrap);
|
||||
if (result.status === 'error') {
|
||||
onError(result.value);
|
||||
}
|
||||
}
|
||||
|
||||
function tryCatch(func, value) {
|
||||
var out = {};
|
||||
try {
|
||||
out.value = func(value);
|
||||
out.status = 'success';
|
||||
} catch (e) {
|
||||
out.status = 'error';
|
||||
out.value = e;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Promise.resolve = resolve;
|
||||
function resolve(value) {
|
||||
if (value instanceof this) {
|
||||
return value;
|
||||
}
|
||||
return handlers.resolve(new this(INTERNAL), value);
|
||||
}
|
||||
|
||||
Promise.reject = reject;
|
||||
function reject(reason) {
|
||||
var promise = new this(INTERNAL);
|
||||
return handlers.reject(promise, reason);
|
||||
}
|
||||
|
||||
Promise.all = all;
|
||||
function all(iterable) {
|
||||
var self = this;
|
||||
if (Object.prototype.toString.call(iterable) !== '[object Array]') {
|
||||
return this.reject(new TypeError('must be an array'));
|
||||
}
|
||||
|
||||
var len = iterable.length;
|
||||
var called = false;
|
||||
if (!len) {
|
||||
return this.resolve([]);
|
||||
}
|
||||
|
||||
var values = new Array(len);
|
||||
var resolved = 0;
|
||||
var i = -1;
|
||||
var promise = new this(INTERNAL);
|
||||
|
||||
while (++i < len) {
|
||||
allResolver(iterable[i], i);
|
||||
}
|
||||
return promise;
|
||||
function allResolver(value, i) {
|
||||
self.resolve(value).then(resolveFromAll, function (error) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
handlers.reject(promise, error);
|
||||
}
|
||||
});
|
||||
function resolveFromAll(outValue) {
|
||||
values[i] = outValue;
|
||||
if (++resolved === len && !called) {
|
||||
called = true;
|
||||
handlers.resolve(promise, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Promise.race = race;
|
||||
function race(iterable) {
|
||||
var self = this;
|
||||
if (Object.prototype.toString.call(iterable) !== '[object Array]') {
|
||||
return this.reject(new TypeError('must be an array'));
|
||||
}
|
||||
|
||||
var len = iterable.length;
|
||||
var called = false;
|
||||
if (!len) {
|
||||
return this.resolve([]);
|
||||
}
|
||||
|
||||
var i = -1;
|
||||
var promise = new this(INTERNAL);
|
||||
|
||||
while (++i < len) {
|
||||
resolver(iterable[i]);
|
||||
}
|
||||
return promise;
|
||||
function resolver(value) {
|
||||
self.resolve(value).then(function (response) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
handlers.resolve(promise, response);
|
||||
}
|
||||
}, function (error) {
|
||||
if (!called) {
|
||||
called = true;
|
||||
handlers.reject(promise, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
},{"1":1}],3:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
/* istanbul ignore next */
|
||||
var MyPromise = typeof Promise !== 'undefined' ? Promise : require(2);
|
||||
|
||||
var messageIds = 0;
|
||||
|
||||
function onMessage(self, e) {
|
||||
var message = e.data;
|
||||
if (!Array.isArray(message) || message.length < 2) {
|
||||
// Ignore - this message is not for us.
|
||||
return;
|
||||
}
|
||||
var messageId = message[0];
|
||||
var error = message[1];
|
||||
var result = message[2];
|
||||
|
||||
var callback = self._callbacks[messageId];
|
||||
|
||||
if (!callback) {
|
||||
// Ignore - user might have created multiple PromiseWorkers.
|
||||
// This message is not for us.
|
||||
return;
|
||||
}
|
||||
|
||||
delete self._callbacks[messageId];
|
||||
callback(error, result);
|
||||
}
|
||||
|
||||
function PromiseWorker(worker) {
|
||||
var self = this;
|
||||
self._worker = worker;
|
||||
self._callbacks = {};
|
||||
|
||||
worker.addEventListener('message', function (e) {
|
||||
onMessage(self, e);
|
||||
});
|
||||
}
|
||||
|
||||
PromiseWorker.prototype.postMessage = function (userMessage, transferList) {
|
||||
var self = this;
|
||||
var messageId = messageIds++;
|
||||
|
||||
var messageToSend = [messageId, userMessage];
|
||||
|
||||
return new MyPromise(function (resolve, reject) {
|
||||
self._callbacks[messageId] = function (error, result) {
|
||||
if (error) {
|
||||
return reject(new Error(error.message));
|
||||
}
|
||||
resolve(result);
|
||||
};
|
||||
/* istanbul ignore if */
|
||||
if (typeof self._worker.controller !== 'undefined') {
|
||||
// service worker, use MessageChannels because e.source is broken in Chrome < 51:
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=543198
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = function (e) {
|
||||
onMessage(self, e);
|
||||
};
|
||||
self._worker.controller.postMessage(messageToSend, [channel.port2].concat(transferList));
|
||||
} else {
|
||||
// web worker
|
||||
self._worker.postMessage(messageToSend, transferList);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
PromiseWorker.prototype.terminate = function () {
|
||||
this._worker.terminate();
|
||||
}
|
||||
|
||||
module.exports = PromiseWorker;
|
||||
},{"2":2}]},{},[3])(3)
|
||||
});
|
||||
1
node_modules/promise-worker-transferable/dist/promise-worker.min.js
generated
vendored
Normal file
1
node_modules/promise-worker-transferable/dist/promise-worker.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
100
node_modules/promise-worker-transferable/dist/promise-worker.register.js
generated
vendored
Normal file
100
node_modules/promise-worker-transferable/dist/promise-worker.register.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
(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.registerPromiseWorker = 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){
|
||||
module.exports = isPromise;
|
||||
|
||||
function isPromise(obj) {
|
||||
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
||||
}
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
var isPromise = require(1);
|
||||
|
||||
function registerPromiseWorker(callback) {
|
||||
|
||||
function postOutgoingMessage(e, messageId, error, result) {
|
||||
function postMessage(msg, transferList) {
|
||||
/* istanbul ignore if */
|
||||
if (typeof self.postMessage !== 'function') { // service worker
|
||||
e.ports[0].postMessage(msg, transferList);
|
||||
} else { // web worker
|
||||
self.postMessage(msg, transferList);
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
/* istanbul ignore else */
|
||||
if (typeof console !== 'undefined' && 'error' in console) {
|
||||
// This is to make errors easier to debug. I think it's important
|
||||
// enough to just leave here without giving the user an option
|
||||
// to silence it.
|
||||
console.error('Worker caught an error:', error);
|
||||
}
|
||||
postMessage([messageId, {
|
||||
message: error.message
|
||||
}]);
|
||||
} else {
|
||||
if (result instanceof MessageWithTransferList) {
|
||||
postMessage([messageId, null, result.message], result.transferList);
|
||||
} else {
|
||||
postMessage([messageId, null, result]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tryCatchFunc(callback, message) {
|
||||
try {
|
||||
return {res: callback(message, withTransferList)};
|
||||
} catch (e) {
|
||||
return {err: e};
|
||||
}
|
||||
}
|
||||
|
||||
function withTransferList(resMessage, transferList) {
|
||||
return new MessageWithTransferList(resMessage, transferList);
|
||||
}
|
||||
|
||||
function handleIncomingMessage(e, callback, messageId, message) {
|
||||
|
||||
var result = tryCatchFunc(callback, message);
|
||||
|
||||
if (result.err) {
|
||||
postOutgoingMessage(e, messageId, result.err);
|
||||
} else if (!isPromise(result.res)) {
|
||||
postOutgoingMessage(e, messageId, null, result.res);
|
||||
} else {
|
||||
result.res.then(function (finalResult) {
|
||||
postOutgoingMessage(e, messageId, null, finalResult);
|
||||
}, function (finalError) {
|
||||
postOutgoingMessage(e, messageId, finalError);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onIncomingMessage(e) {
|
||||
var payload = e.data;
|
||||
if (!Array.isArray(payload) || payload.length !== 2) {
|
||||
// message doens't match communication format; ignore
|
||||
return;
|
||||
}
|
||||
var messageId = payload[0];
|
||||
var message = payload[1];
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
postOutgoingMessage(e, messageId, new Error(
|
||||
'Please pass a function into register().'));
|
||||
} else {
|
||||
handleIncomingMessage(e, callback, messageId, message);
|
||||
}
|
||||
}
|
||||
|
||||
function MessageWithTransferList(message, transferList) {
|
||||
this.message = message;
|
||||
this.transferList = transferList;
|
||||
}
|
||||
|
||||
self.addEventListener('message', onIncomingMessage);
|
||||
}
|
||||
|
||||
module.exports = registerPromiseWorker;
|
||||
},{"1":1}]},{},[2])(2)
|
||||
});
|
||||
1
node_modules/promise-worker-transferable/dist/promise-worker.register.min.js
generated
vendored
Normal file
1
node_modules/promise-worker-transferable/dist/promise-worker.register.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.registerPromiseWorker=e()}}(function(){return function e(n,r,t){function o(i,s){if(!r[i]){if(!n[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(f)return f(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var a=r[i]={exports:{}};n[i][0].call(a.exports,function(e){var r=n[i][1][e];return o(r?r:e)},a,a.exports,e,n,r,t)}return r[i].exports}for(var f="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(e,n,r){function t(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}n.exports=t},{}],2:[function(e,n,r){"use strict";function t(e){function n(e,n,r,t){function o(n,r){"function"!=typeof self.postMessage?e.ports[0].postMessage(n,r):self.postMessage(n,r)}r?("undefined"!=typeof console&&"error"in console&&console.error("Worker caught an error:",r),o([n,{message:r.message}])):t instanceof s?o([n,null,t.message],t.transferList):o([n,null,t])}function r(e,n){try{return{res:e(n,t)}}catch(e){return{err:e}}}function t(e,n){return new s(e,n)}function f(e,t,f,i){var s=r(t,i);s.err?n(e,f,s.err):o(s.res)?s.res.then(function(r){n(e,f,null,r)},function(r){n(e,f,r)}):n(e,f,null,s.res)}function i(r){var t=r.data;if(Array.isArray(t)&&2===t.length){var o=t[0],i=t[1];"function"!=typeof e?n(r,o,new Error("Please pass a function into register().")):f(r,e,o,i)}}function s(e,n){this.message=e,this.transferList=n}self.addEventListener("message",i)}var o=e(1);n.exports=t},{1:1}]},{},[2])(2)});
|
||||
73
node_modules/promise-worker-transferable/index.js
generated
vendored
Normal file
73
node_modules/promise-worker-transferable/index.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
/* istanbul ignore next */
|
||||
var MyPromise = typeof Promise !== 'undefined' ? Promise : require('lie');
|
||||
|
||||
var messageIds = 0;
|
||||
|
||||
function onMessage(self, e) {
|
||||
var message = e.data;
|
||||
if (!Array.isArray(message) || message.length < 2) {
|
||||
// Ignore - this message is not for us.
|
||||
return;
|
||||
}
|
||||
var messageId = message[0];
|
||||
var error = message[1];
|
||||
var result = message[2];
|
||||
|
||||
var callback = self._callbacks[messageId];
|
||||
|
||||
if (!callback) {
|
||||
// Ignore - user might have created multiple PromiseWorkers.
|
||||
// This message is not for us.
|
||||
return;
|
||||
}
|
||||
|
||||
delete self._callbacks[messageId];
|
||||
callback(error, result);
|
||||
}
|
||||
|
||||
function PromiseWorker(worker) {
|
||||
var self = this;
|
||||
self._worker = worker;
|
||||
self._callbacks = {};
|
||||
|
||||
worker.addEventListener('message', function (e) {
|
||||
onMessage(self, e);
|
||||
});
|
||||
}
|
||||
|
||||
PromiseWorker.prototype.postMessage = function (userMessage, transferList) {
|
||||
var self = this;
|
||||
var messageId = messageIds++;
|
||||
|
||||
var messageToSend = [messageId, userMessage];
|
||||
|
||||
return new MyPromise(function (resolve, reject) {
|
||||
self._callbacks[messageId] = function (error, result) {
|
||||
if (error) {
|
||||
return reject(new Error(error.message));
|
||||
}
|
||||
resolve(result);
|
||||
};
|
||||
/* istanbul ignore if */
|
||||
if (typeof self._worker.controller !== 'undefined') {
|
||||
// service worker, use MessageChannels because e.source is broken in Chrome < 51:
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=543198
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = function (e) {
|
||||
onMessage(self, e);
|
||||
};
|
||||
self._worker.controller.postMessage(messageToSend, [channel.port2].concat(transferList));
|
||||
} else {
|
||||
// web worker
|
||||
self._worker.postMessage(messageToSend, transferList);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
PromiseWorker.prototype.terminate = function () {
|
||||
this._worker.terminate();
|
||||
}
|
||||
|
||||
module.exports = PromiseWorker;
|
||||
70
node_modules/promise-worker-transferable/package.json
generated
vendored
Normal file
70
node_modules/promise-worker-transferable/package.json
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "promise-worker-transferable",
|
||||
"version": "1.0.4",
|
||||
"description": "Communicate with a Web Worker using Promises, allowing transferList",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"prepublish": "npm run build",
|
||||
"build": "rimraf dist && mkdirp dist && browserify -s PromiseWorker -p bundle-collapser/plugin . > dist/promise-worker.js && browserify -s registerPromiseWorker -p bundle-collapser/plugin register.js > dist/promise-worker.register.js && uglifyjs -mc < dist/promise-worker.js > dist/promise-worker.min.js && uglifyjs -mc < dist/promise-worker.register.js > dist/promise-worker.register.min.js",
|
||||
"build-test": "node bin/build-worker-bundles.js",
|
||||
"test": "npm run build-test && mocha test/test.js",
|
||||
"test-local": "npm run build-test && zuul --local 9000 --no-coverage test/test.js",
|
||||
"test-phantom": "npm run build-test && zuul --phantom --no-coverage test/test.js",
|
||||
"test-browser": "npm run build-test && zuul --no-coverage ./test/test.js",
|
||||
"lint": "jshint -c .jshintrc *.js",
|
||||
"istanbul-combine": "istanbul-combine -d coverage -r json coverage/coverage.json coverage/coverage-worker.json && mv coverage/coverage-final.json coverage/coverage.json && rimraf coverage/coverage-worker.json",
|
||||
"istanbul-check": "istanbul check-coverage --lines 100 --function 100 --statements 100 --branches 100",
|
||||
"test-for-coverage": "istanbul cover ./node_modules/.bin/_mocha ./test/test.js",
|
||||
"istanbul-report": "istanbul report lcov",
|
||||
"coverage": "COVERAGE=1 run-scripts build-test test-for-coverage istanbul-combine istanbul-report istanbul-check",
|
||||
"report-coverage": "npm run coverage && istanbul-coveralls"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/terikon/promise-worker-transferable.git"
|
||||
},
|
||||
"keywords": [
|
||||
"web worker",
|
||||
"promise",
|
||||
"webworker",
|
||||
"worker"
|
||||
],
|
||||
"author": "Roman Viskin <npm@terikon.com>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/terikon/promise-worker-transferable/issues"
|
||||
},
|
||||
"homepage": "https://github.com/terikon/promise-worker-transferable#readme",
|
||||
"devDependencies": {
|
||||
"assert": "^1.3.0",
|
||||
"browserify": "^13.0.1",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"denodeify": "^1.2.1",
|
||||
"glob-promise": "^1.0.6",
|
||||
"istanbul": "^0.4.2",
|
||||
"istanbul-combine": "^0.3.0",
|
||||
"istanbul-coveralls": "^1.0.3",
|
||||
"istanbulify": "^0.1.0",
|
||||
"jshint": "2.8.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^2.4.5",
|
||||
"phantomjs-prebuilt": "^2.1.5",
|
||||
"pseudo-worker": "^1.1.0",
|
||||
"rimraf": "^2.5.3",
|
||||
"run-scripts": "^0.4.0",
|
||||
"stream-to-promise": "^1.1.0",
|
||||
"uglify-js": "^2.7.0",
|
||||
"zuul": "^3.10.1",
|
||||
"zuul-localtunnel": "nolanlawson/zuul-localtunnel#https",
|
||||
"text-encoding": "^0.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-promise": "^2.1.0",
|
||||
"lie": "^3.0.2"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"register.js",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
90
node_modules/promise-worker-transferable/register.js
generated
vendored
Normal file
90
node_modules/promise-worker-transferable/register.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
|
||||
var isPromise = require('is-promise');
|
||||
|
||||
function registerPromiseWorker(callback) {
|
||||
|
||||
function postOutgoingMessage(e, messageId, error, result) {
|
||||
function postMessage(msg, transferList) {
|
||||
/* istanbul ignore if */
|
||||
if (typeof self.postMessage !== 'function') { // service worker
|
||||
e.ports[0].postMessage(msg, transferList);
|
||||
} else { // web worker
|
||||
self.postMessage(msg, transferList);
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
/* istanbul ignore else */
|
||||
if (typeof console !== 'undefined' && 'error' in console) {
|
||||
// This is to make errors easier to debug. I think it's important
|
||||
// enough to just leave here without giving the user an option
|
||||
// to silence it.
|
||||
console.error('Worker caught an error:', error);
|
||||
}
|
||||
postMessage([messageId, {
|
||||
message: error.message
|
||||
}]);
|
||||
} else {
|
||||
if (result instanceof MessageWithTransferList) {
|
||||
postMessage([messageId, null, result.message], result.transferList);
|
||||
} else {
|
||||
postMessage([messageId, null, result]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tryCatchFunc(callback, message) {
|
||||
try {
|
||||
return {res: callback(message, withTransferList)};
|
||||
} catch (e) {
|
||||
return {err: e};
|
||||
}
|
||||
}
|
||||
|
||||
function withTransferList(resMessage, transferList) {
|
||||
return new MessageWithTransferList(resMessage, transferList);
|
||||
}
|
||||
|
||||
function handleIncomingMessage(e, callback, messageId, message) {
|
||||
|
||||
var result = tryCatchFunc(callback, message);
|
||||
|
||||
if (result.err) {
|
||||
postOutgoingMessage(e, messageId, result.err);
|
||||
} else if (!isPromise(result.res)) {
|
||||
postOutgoingMessage(e, messageId, null, result.res);
|
||||
} else {
|
||||
result.res.then(function (finalResult) {
|
||||
postOutgoingMessage(e, messageId, null, finalResult);
|
||||
}, function (finalError) {
|
||||
postOutgoingMessage(e, messageId, finalError);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function onIncomingMessage(e) {
|
||||
var payload = e.data;
|
||||
if (!Array.isArray(payload) || payload.length !== 2) {
|
||||
// message doens't match communication format; ignore
|
||||
return;
|
||||
}
|
||||
var messageId = payload[0];
|
||||
var message = payload[1];
|
||||
|
||||
if (typeof callback !== 'function') {
|
||||
postOutgoingMessage(e, messageId, new Error(
|
||||
'Please pass a function into register().'));
|
||||
} else {
|
||||
handleIncomingMessage(e, callback, messageId, message);
|
||||
}
|
||||
}
|
||||
|
||||
function MessageWithTransferList(message, transferList) {
|
||||
this.message = message;
|
||||
this.transferList = transferList;
|
||||
}
|
||||
|
||||
self.addEventListener('message', onIncomingMessage);
|
||||
}
|
||||
|
||||
module.exports = registerPromiseWorker;
|
||||
Reference in New Issue
Block a user