wpoll
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

WPoll

Lines of code GitHub top language NPM GitHub last commit

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

Package Sidebar

Install

npm i wpoll

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

10.5 kB

Total Files

12

Last publish

Collaborators

  • le-ar