low: async pool
betula opened this issue · comments
Slava Bereza commented
This task started from the idea and hypothesis possible syntax:
const info = pool(async () => {
return await search(...)
});
// info.proc - parallel process count
// info.pending - proc > 0
// info.stop() - function for stop all async process in pool
// info.run() - function for execute in async pool
// [ run ] // length > 0 for array destruction detect
// // info.data?
// // info.error?
// And possible to call `info` equivalents as info.run (I think function inheritance in throttle and debounce possible)
info.run();
assert(info.proc === 1);
assert(info.pending === true);
// It's possible that pure `pool` not so interesting for use.
pool.single(async ({ cancelled }) => {
const zip = await search();
if (cancelled()) return;
return await unpack(zip);
});
// If exists active promise each query return It
// pool.throttle(150, async ({ cancelled, abortController?.., cancel }) => {
pool.throttle(150, async ({ stopped, abortController?.., stop }) => {
const zip = await search();
if (zip === 0) stop();
if (stopped()) return;
return await unpack(zip);
});
pool.debounce(150, async function * ({ cancel }) {
const zip = yield search();
if (zip === 0) cancel();
return yield unpack(zip);
});
Slava Bereza commented
It is offtopic, but I want to think about throttle and debounce for signals:
const start = signal();
const delayedStart = signal.throttle(150, start);
const a = value();
const delayedA = value.throttle(150, a);
const p = pool(async () => await search());
const delayedP = pool.throttle(150, p);
Maybe only one throttle
function for all necessaries.
Slava Bereza commented
#32 - basic pool implementation ready
Slava Bereza commented
0d76b0a - pool values changed to entities
const run = pool(async () => {
// const stop = stoppable();
return await search(...)
});
run.pending.watch(console.log);
run.count.watch(console.log);
run.threads.watch(console.log);
console.log(await run())
Slava Bereza commented
Added to "the stream of conciseness 0.7+ roadmap"