josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.04k stars 148 forks source link

add execDirect #442

Closed frankie-zeng closed 4 months ago

frankie-zeng commented 4 months ago

allow multi task run in worker at same time

var workerpool = require('../../');
var ac
function start() {
  ac=new AbortController();
  return new Promise(function (resolve, reject) {
    ac.signal.onabort = () => {
        resolve('aborted');
    };
});  
}
function stop() {
  ac.abort();
}

// create a worker and register some functions
workerpool.worker({
    start: start,
    stop:stop
});
pool.execDirect('start',[]).then((val)=>{
      assert.strictEqual(val,'aborted');
      done();
    }).catch(done)
    pool.execDirect('stop',[])
josdejong commented 4 months ago

Thanks for your PR. Can you elaborate on what the PR does? Is it about adding support for an AbortController like in #441?

I see you deleted test files Pool.test.js and Promis.test.js, that should not be done. These test files are necessary to ensure the behavior of the library is as we want.

josdejong commented 4 months ago

?

frankie-zeng commented 4 months ago

?

I will fix the code and reopen a new PR. thanks.

josdejong commented 4 months ago

Ok!