Last active
May 28, 2019 17:07
-
-
Save leofab86/0a383d3b86d832c47f5b44a27071c137 to your computer and use it in GitHub Desktop.
Fuzzy search automcomplete v1.2.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
//workerArrayController.js | |
export default class WorkerArrayController { | |
constructor ({data, handleResults, arraySize}) { | |
this.workerArray = new Worker('... path to workerArray.js'); | |
let i = 1; | |
this.webWorkers = {}; | |
while (i <= arraySize) { | |
const workerName = `ww${i}`; | |
this.webWorkers[workerName] = new Worker(`...path to ww1.js`); | |
/* Creates a MessageChannel for each worker and passes that channel's | |
ports to both workerArray dispatcher and the worker so | |
they can communicate with each other */ | |
const channel = new MessageChannel(); | |
this.workerArray.postMessage({workerName}, [channel.port1]); | |
this.webWorkers[workerName].postMessage({data}, [channel.port2]); | |
i++; | |
} | |
this.workerArray.onmessage = handleResults; | |
} | |
search = (searchTerm) => { | |
this.workerArray.postMessage({searchTerm}); | |
} | |
terminate() { | |
this.workerArray.terminate(); | |
for (const workerName in this.webWorkers) { | |
this.webWorkers[workerName].terminate(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment