@pipegpu/worker
v0.1.3
Published
[](https://badge.fury.io/js/pipegpu.worker)
Readme
pipegpu.worker
Example
import { WorkerLib } from '../src/WorkerLib';
import { LongtermWorkerPool } from '../src/WorkerPool';
import type { IMessagebus } from '../src/WorkerProtocol';
import InitHDMFWorker from '../workers/hdmf_worker.ts?worker';
(async () => {
const now = performance.now();
let cost: number = 0;
const totalSteps = 100;
WorkerLib.Instance.setWorker(`REQUEST_INSTANCE`, InitHDMFWorker);
// set thread num as: LongtermWorkerPool.workerInit(['REQUEST_INSTANCE'], 4);
LongtermWorkerPool.workerInit(['REQUEST_INSTANCE']);
let step = 0;
const Tick = async () => {
const uri = `http://127.0.0.1/ceshi_1_3_4/`;
const dir = `mesh`;
const id = `00311c8bca15f4c62900894e8e402047e08ab5956b9e61208f01417cf83959b1`;
if (LongtermWorkerPool.hasIdleWorker(`REQUEST_INSTANCE`)) {
const worker = LongtermWorkerPool.acquireWorker(`REQUEST_INSTANCE`, {
workerKey: id,
args: [uri, dir, id]
});
worker?.then((msgBus: IMessagebus) => {
step++;
if (step === totalSteps) {
cost = performance.now() - now;
document.body.innerText = `complete: ${cost}ms /${totalSteps},${msgBus.msg}ms`;
} else if (step < totalSteps) {
document.body.innerText = `step: ${step}/${totalSteps},${msgBus.msg}ms`;
}
else {
document.body.innerText = `complete: ${cost} ms /${totalSteps},${msgBus.msg}ms`;
}
});
}
requestAnimationFrame(Tick);
};
// do request in each frame
Tick();
})();
