Last active
January 31, 2016 15:57
-
-
Save asciidisco/047ec1c9f430174c64b0 to your computer and use it in GitHub Desktop.
WebWorker Feature Check
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
self.onmessage = ({data}) => { | |
self.postMessage(data.reduce((o, v, i) => { | |
o[v] = !!self[v] | |
return o; | |
}, {})); | |
}; |
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
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