wpoll
v1.0.3
Published
Worker Poll With Timeout
Downloads
2
Maintainers
Readme
WPoll
Worker poll use worker_threads
Example
- main.ts
import { WPoll } from 'wpoll';
import path from 'path';
let wpoll = new WPoll<number>(path.resolve(__dirname, './worker.js'));
wpoll.init();
(async () => {
console.log(await wpoll.exec(100));
})();
- worker.ts
import { WWorker } from 'wpoll';
new WWorker(async (message) => {
console.log(message);
return 5;
});
Types
WPoll<T = void, P = void>
|Name|Parameter|Type|Description| |---|---|---|---| |Constructor||WPoll<T, P>| ||workerFile|string|Path to worker file (absolute path preferred)| ||props|WPollProps|Init Parameters |init|-|-|Init Workers. Must be called once| |exec|T|P|Execute with parameters T and return P
WWorker<T = void, P = void>
|Name|Parameter|Type|Description| |---|---|---|---| |Constructor||WWorker<T,P> ||onMessage|(message: T) => Promise<P> | P| callback on message received