mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-08 21:20:41 +02:00
fix node.js worker threads
This commit is contained in:
3
dist/node/node.js
vendored
3
dist/node/node.js
vendored
@@ -8,6 +8,7 @@ parentPort.on("message", function(data){
|
||||
/** @type Index */
|
||||
const args = data["args"];
|
||||
const task = data["task"];
|
||||
const id = data["id"];
|
||||
|
||||
switch(task){
|
||||
|
||||
@@ -29,6 +30,6 @@ parentPort.on("message", function(data){
|
||||
default:
|
||||
|
||||
const message = index[task].apply(index, args);
|
||||
parentPort.postMessage(task === "search" ? message : null);
|
||||
parentPort.postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id });
|
||||
}
|
||||
});
|
||||
|
@@ -31,7 +31,7 @@
|
||||
"copy": "npm run clean && cpx \"src/**\" tmp/",
|
||||
"clean": "if exist tmp rmdir tmp /s /q && mkdir tmp",
|
||||
"build": "npm run copy && npm run build:bundle",
|
||||
"build:bundle": "node task/build RELEASE=bundle",
|
||||
"build:bundle": "node task/build RELEASE=bundle && cpx \"src/worker/node.js\" dist/node/",
|
||||
"build:debug": "node task/build RELEASE=debug COMPILATION_LEVEL=SIMPLE FORMATTING=PRETTY_PRINT",
|
||||
"build:compact": "node task/build RELEASE=compact",
|
||||
"build:light": "node task/build RELEASE=light",
|
||||
|
@@ -20,15 +20,13 @@ import { IndexInterface } from "./type.js";
|
||||
import { encode as default_encoder } from "./lang/latin/default.js";
|
||||
import { create_object, create_object_array, concat, sort_by_length_down, is_array, is_string, is_object, parse_option } from "./common.js";
|
||||
import { pipeline, init_stemmer_or_matcher, init_filter } from "./lang.js";
|
||||
import { registerCharset, global_lang, global_charset } from "./global.js";
|
||||
import { global_lang, global_charset } from "./global.js";
|
||||
import apply_async from "./async.js";
|
||||
import { intersect } from "./intersect.js";
|
||||
import Cache, { searchCache } from "./cache.js";
|
||||
import apply_preset from "./preset.js";
|
||||
import { exportIndex, importIndex } from "./serialize.js";
|
||||
|
||||
//registerCharset("latin:default", default_encoder);
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements IndexInterface
|
||||
|
@@ -47,10 +47,5 @@ export default function(data) {
|
||||
const id = data["id"];
|
||||
const message = index[task].apply(index, args);
|
||||
postMessage(task === "search" ? { "id": id, "msg": message } : { "id": id });
|
||||
|
||||
// if(task === "search"){
|
||||
//
|
||||
// postMessage(message);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
@@ -2,7 +2,7 @@
|
||||
import { create_object, is_function, is_object, is_string } from "../common.js";
|
||||
import handler from "./handler.js";
|
||||
|
||||
let counter = 0;
|
||||
let pid = 0;
|
||||
|
||||
/**
|
||||
* @param {Object=} options
|
||||
@@ -68,7 +68,6 @@ function WorkerIndex(options){
|
||||
this.worker.postMessage({
|
||||
|
||||
"task": "init",
|
||||
//"id": ++counter,
|
||||
"factory": factory,
|
||||
"options": options
|
||||
});
|
||||
@@ -102,22 +101,13 @@ function register(key){
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
self.resolver[++counter] = resolve;
|
||||
self.resolver[++pid] = resolve;
|
||||
self.worker.postMessage({
|
||||
|
||||
"task": key,
|
||||
"id": counter,
|
||||
"id": pid,
|
||||
"args": args
|
||||
});
|
||||
|
||||
// if(key === "search"){
|
||||
//
|
||||
// self.resolve = resolve;
|
||||
// }
|
||||
// else{
|
||||
//
|
||||
// resolve();
|
||||
// }
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user