allow engine to override work/pool urls and control threading
This commit is contained in:
parent
0022bffc20
commit
50e7e88d95
9 changed files with 44 additions and 235 deletions
|
|
@ -6,7 +6,7 @@ import STACKS from './stacks.js';
|
|||
|
||||
import { broker } from '../moto/broker.js';
|
||||
import { client as work } from './client.js';
|
||||
import { consts, COLOR as color, LISTS as lists, MODES, VIEWS } from './consts.js';
|
||||
import { consts, COLOR as color, LISTS as lists, MODES, VIEWS, PATHS } from './consts.js';
|
||||
import { device, devices } from './devices.js';
|
||||
import { catalog, dialog, event, group, help, hide, image } from './main.js';
|
||||
import { modal, mode, probe, process, show, space, util, view } from './main.js';
|
||||
|
|
@ -130,7 +130,7 @@ export const api = {
|
|||
clone,
|
||||
color,
|
||||
conf: settings.conf,
|
||||
const: { LANG, LISTS: lists, LOCAL, MODES, SETUP, SECURE, STACKS, VIEWS },
|
||||
const: { LANG, LOCAL, SETUP, SECURE, STACKS, ...consts },
|
||||
devel,
|
||||
device,
|
||||
devices,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ let debug = self.debug === true,
|
|||
running = {},
|
||||
worker = null,
|
||||
minions = false,
|
||||
restarting = false;
|
||||
restarting = false,
|
||||
workpath,
|
||||
poolpath;
|
||||
|
||||
/**
|
||||
* @param {Function} fn name of function in kiri.worker
|
||||
|
|
@ -45,10 +47,20 @@ function send(fn, data, onreply, zerocopy) {
|
|||
export const client = {
|
||||
send: send,
|
||||
|
||||
setWorkPath(path) {
|
||||
workpath = path;
|
||||
return client;
|
||||
},
|
||||
|
||||
setPoolPath(path) {
|
||||
poolpath = path;
|
||||
return client;
|
||||
},
|
||||
|
||||
pool: {
|
||||
start() {
|
||||
minions = true;
|
||||
send("pool_start", {}, noop);
|
||||
send("pool_start", { url: poolpath }, noop);
|
||||
},
|
||||
|
||||
stop() {
|
||||
|
|
@ -65,7 +77,7 @@ export const client = {
|
|||
const blob = new Blob([ work ], { type: 'application/javascript' });
|
||||
return new Worker(URL.createObjectURL(blob));
|
||||
} else {
|
||||
let worker = new Worker(`/lib/kiri-run/worker.js`, { type: 'module' });
|
||||
let worker = new Worker(workpath || api.const.PATHS.work, { type: 'module' });
|
||||
worker.onerror = (error) => {
|
||||
console.log({ WORKER_ERROR: error });
|
||||
error.preventDefault();
|
||||
|
|
@ -87,6 +99,10 @@ export const client = {
|
|||
return current > 0;
|
||||
},
|
||||
|
||||
start() {
|
||||
client.restart();
|
||||
},
|
||||
|
||||
restart() {
|
||||
// prevent re-entry from cancel callback
|
||||
if (restarting) {
|
||||
|
|
@ -334,9 +350,6 @@ export const client = {
|
|||
}
|
||||
};
|
||||
|
||||
// start worker
|
||||
client.restart();
|
||||
|
||||
self.kiri_client = client;
|
||||
|
||||
export default client;
|
||||
|
|
|
|||
|
|
@ -141,16 +141,22 @@ const PMODES = {
|
|||
TOOLS: 2
|
||||
};
|
||||
|
||||
const PATHS = {
|
||||
work: "/lib/kiri-run/worker.js",
|
||||
pool: "/lib/kiri-run/minion.js"
|
||||
};
|
||||
|
||||
const SEED = 'kiri-seed';
|
||||
|
||||
export let consts = {
|
||||
PMODES,
|
||||
COLOR,
|
||||
LISTS,
|
||||
MODES,
|
||||
PATHS,
|
||||
PMODES,
|
||||
VIEWS,
|
||||
SEED,
|
||||
beltfact: Math.cos(Math.PI / 4)
|
||||
};
|
||||
|
||||
export { COLOR, LISTS, MODES, VIEWS, PMODES, SEED };
|
||||
export { COLOR, LISTS, MODES, VIEWS, PATHS, PMODES, SEED };
|
||||
|
|
|
|||
|
|
@ -2166,5 +2166,6 @@ function init_lang() {
|
|||
|
||||
export function run() {
|
||||
init_lang();
|
||||
client.start();
|
||||
return api;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue