-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update a bunch of stuff for 2.0.0 (#28)
- don't include promise polyfill - fix tests - switch to standard js - add changelog - fix package.json files fixes #17
- Loading branch information
1 parent
e5d9c5d
commit e7308f7
Showing
19 changed files
with
8,830 additions
and
297 deletions.
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
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
ui: mocha-bdd | ||
concurrency: 1 | ||
tunnel: | ||
type: localtunnel | ||
https: true | ||
type: ngrok | ||
browsers: | ||
- name: chrome | ||
version: 42..latest | ||
version: latest | ||
- name: firefox | ||
version: 45..latest | ||
version: latest | ||
- name: safari | ||
version: [8, 9..latest] | ||
version: latest | ||
- name: ie | ||
version: 10..latest | ||
- name: microsoftedge | ||
version: 13..latest | ||
version: latest | ||
- name: iphone | ||
version: [8.4, 9.2] | ||
- name: ipad | ||
version: [8.4, 9.2] | ||
version: latest | ||
- name: android | ||
version: 4.4..latest | ||
version: 4.4 |
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,13 @@ | ||
Changelog | ||
==== | ||
|
||
v2.0.0 | ||
--- | ||
|
||
- Stopped stringifying worker messages ([#14](https://github.com/nolanlawson/promise-worker/pull/14)) | ||
- Removed built-in Promise polyfill | ||
|
||
v1.0.0 | ||
--- | ||
|
||
- Initial release |
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
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
var Promise = require('lie'); | ||
var denodeify = require('denodeify'); | ||
var rimraf = denodeify(require('rimraf')); | ||
var mkdirp = denodeify(require('mkdirp')); | ||
var glob = require('glob-promise'); | ||
var streamToPromise = require('stream-to-promise'); | ||
var browserify = require('browserify'); | ||
var fs = require('fs'); | ||
var writeFile = denodeify(fs.writeFile); | ||
var path = require('path'); | ||
var Promise = require('lie') | ||
var denodeify = require('denodeify') | ||
var rimraf = denodeify(require('rimraf')) | ||
var mkdirp = denodeify(require('mkdirp')) | ||
var glob = require('glob-promise') | ||
var streamToPromise = require('stream-to-promise') | ||
var browserify = require('browserify') | ||
var fs = require('fs') | ||
var writeFile = denodeify(fs.writeFile) | ||
var path = require('path') | ||
|
||
Promise.resolve().then(function () { | ||
return rimraf('test/bundle'); | ||
return rimraf('test/bundle') | ||
}).then(function () { | ||
return mkdirp('test/bundle'); | ||
return mkdirp('test/bundle') | ||
}).then(function () { | ||
return glob('test/worker*js'); | ||
return glob('test/worker*js') | ||
}).then(function (files) { | ||
return Promise.all(files.map(function (file) { | ||
var b = browserify(file, {debug: true}); | ||
var b = browserify(file, { debug: true }) | ||
if (process.env.COVERAGE === '1') { | ||
b = b.transform('istanbulify'); | ||
b = b.transform('istanbulify') | ||
} | ||
b = b.bundle(); | ||
b = b.bundle() | ||
return streamToPromise(b).then(function (buff) { | ||
var outputFile = 'bundle-' + path.basename(file); | ||
return writeFile(outputFile, buff, 'utf-8'); | ||
}); | ||
})); | ||
var outputFile = 'bundle-' + path.basename(file) | ||
return writeFile(outputFile, buff, 'utf-8') | ||
}) | ||
})) | ||
}).catch(function (err) { | ||
console.log(err.stack); | ||
}); | ||
console.log(err.stack) | ||
}) |
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 |
---|---|---|
@@ -1,70 +1,67 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
/* istanbul ignore next */ | ||
var MyPromise = typeof Promise !== 'undefined' ? Promise : require('lie'); | ||
var messageIds = 0 | ||
|
||
var messageIds = 0; | ||
|
||
function onMessage(self, e) { | ||
var message = e.data; | ||
function onMessage (self, e) { | ||
var message = e.data | ||
if (!Array.isArray(message) || message.length < 2) { | ||
// Ignore - this message is not for us. | ||
return; | ||
return | ||
} | ||
var messageId = message[0]; | ||
var error = message[1]; | ||
var result = message[2]; | ||
var messageId = message[0] | ||
var error = message[1] | ||
var result = message[2] | ||
|
||
var callback = self._callbacks[messageId]; | ||
var callback = self._callbacks[messageId] | ||
|
||
if (!callback) { | ||
// Ignore - user might have created multiple PromiseWorkers. | ||
// This message is not for us. | ||
return; | ||
return | ||
} | ||
|
||
delete self._callbacks[messageId]; | ||
callback(error, result); | ||
delete self._callbacks[messageId] | ||
callback(error, result) | ||
} | ||
|
||
function PromiseWorker(worker) { | ||
var self = this; | ||
self._worker = worker; | ||
self._callbacks = {}; | ||
function PromiseWorker (worker) { | ||
var self = this | ||
self._worker = worker | ||
self._callbacks = {} | ||
|
||
worker.addEventListener('message', function (e) { | ||
onMessage(self, e); | ||
}); | ||
onMessage(self, e) | ||
}) | ||
} | ||
|
||
PromiseWorker.prototype.postMessage = function (userMessage) { | ||
var self = this; | ||
var messageId = messageIds++; | ||
var self = this | ||
var messageId = messageIds++ | ||
|
||
var messageToSend = [messageId, userMessage]; | ||
var messageToSend = [messageId, userMessage] | ||
|
||
return new MyPromise(function (resolve, reject) { | ||
return new Promise(function (resolve, reject) { | ||
self._callbacks[messageId] = function (error, result) { | ||
if (error) { | ||
return reject(new Error(error.message)); | ||
return reject(new Error(error.message)) | ||
} | ||
resolve(result); | ||
}; | ||
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(); | ||
var channel = new MessageChannel() | ||
channel.port1.onmessage = function (e) { | ||
onMessage(self, e); | ||
}; | ||
self._worker.controller.postMessage(messageToSend, [channel.port2]); | ||
onMessage(self, e) | ||
} | ||
self._worker.controller.postMessage(messageToSend, [channel.port2]) | ||
} else { | ||
// web worker | ||
self._worker.postMessage(messageToSend); | ||
self._worker.postMessage(messageToSend) | ||
} | ||
}); | ||
}; | ||
}) | ||
} | ||
|
||
module.exports = PromiseWorker; | ||
module.exports = PromiseWorker |
Oops, something went wrong.