Chore: destroy worker thread

This commit is contained in:
SukkaW
2022-09-23 00:07:38 +08:00
parent 8a7f32e2cd
commit 7cec542320
4 changed files with 37 additions and 29 deletions

View File

@@ -1,16 +1,15 @@
const { workerData, move } = require('piscina');
const Piscina = require('piscina');
// pre check if fullset domain is starts with a "."
// This avoid calling chatCodeAt repeatedly
// workerData is an array of string. Sort it by length, short first:
const fullsetDomainStartsWithADot = workerData.filter(domain => (
const fullsetDomainStartsWithADot = Piscina.workerData.filter(domain => (
domain.charCodeAt(0) === 46
&& !canExcludeFromDedupe(domain)
));
const totalLen = fullsetDomainStartsWithADot.length;
module.exports = ({ chunk }) => {
module.exports.dedupe = ({ chunk }) => {
const chunkLength = chunk.length;
const outputToBeRemoved = new Int8Array(chunkLength);
@@ -61,11 +60,11 @@ module.exports = ({ chunk }) => {
}
}
return move(outputToBeRemoved);
return outputToBeRemoved;
};
// duckdns.org domain will not overlap and doesn't need dedupe
function canExcludeFromDedupe(domain) {
function canExcludeFromDedupe (domain) {
if (domain.length === 23 && domain.endsWith('.duckdns.org')) {
return true;
}