Skip to content

Instantly share code, notes, and snippets.

@asciidisco
Last active January 31, 2016 15:57
Show Gist options
  • Save asciidisco/047ec1c9f430174c64b0 to your computer and use it in GitHub Desktop.
Save asciidisco/047ec1c9f430174c64b0 to your computer and use it in GitHub Desktop.
WebWorker Feature Check
self.onmessage = ({data}) => {
self.postMessage(data.reduce((o, v, i) => {
o[v] = !!self[v]
return o;
}, {}));
};
let checkWorkerFeatures = (features) => {
return new Promise((resolve, reject) => {
const threadCheck = new Worker('feature.thread.js');
threadCheck.onmessage = ({data}) => resolve(data) && threadCheck.terminate();
threadCheck.postMessage(features);
})
};
checkWorkerFeatures(['WebSocket', 'localStorage', 'indexedDB']).then(console.log.bind(console));
// Logs: `Object {WebSocket: true, localStorage: false, indexedDB: true}` in latest Chrome:stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment