How to use the workerpool.Promise function in workerpool

To help you get started, we’ve selected a few workerpool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CodeChain-io / codechain-indexer / src / models / logic / utils / workerpool.ts View on Github external
signerPubKey.map(
                    async (
                        signerPubKey: string
                    ): Promise<[string | null, string]> => {
                        const regularKeyOwner = await getRegularKeyOwnerByPublicKey(
                            signerPubKey,
                            options
                        );
                        return [regularKeyOwner, signerPubKey];
                    }
                )
            );
        })
    );

    const chunks: string[][] = (await workerpool.Promise.all(
        regularKeyOwnerAndPubKeys.map(
            (
                chunk: [string | null, string][]
            ): workerpool.Promise => {
                return pool.exec(getSignersFromPubKeyAndRegularKeyOwner, [
                    chunk.map(([regularKeyOwner, signerPubKey]) => {
                        return {
                            regularKeyOwner,
                            signerPubKey
                        };
                    }),
                    networkId
                ]);
            }
        )
    )) as any; // The bug of workerpool type definition
github DefinitelyTyped / DefinitelyTyped / types / workerpool / workerpool-tests.ts View on Github external
const workers = {add, hello};
type IWorkers = typeof workers;
pool.proxy().then((proxy) => {
    proxy.add(1, 2);
    proxy.hello();
});

pool.proxy().then((proxy) => {
    proxy.add(1, 2);
    proxy.hello();
});

new wp.Promise.CancellationError();
new wp.Promise.TimeoutError();

let promises: wp.Promise = wp.Promise.all([
    pool.exec('foo', null),
    pool.exec('foo', null),
    pool.exec('foo', null)
]);
promises = wp.Promise.all([]);
github DefinitelyTyped / DefinitelyTyped / types / workerpool / workerpool-tests.ts View on Github external
pool.exec(hello, [])
    .then((s: string) => s);

const workers = {add, hello};
type IWorkers = typeof workers;
pool.proxy().then((proxy) => {
    proxy.add(1, 2);
    proxy.hello();
});

pool.proxy().then((proxy) => {
    proxy.add(1, 2);
    proxy.hello();
});

new wp.Promise.CancellationError();
new wp.Promise.TimeoutError();

let promises: wp.Promise = wp.Promise.all([
    pool.exec('foo', null),
    pool.exec('foo', null),
    pool.exec('foo', null)
]);
promises = wp.Promise.all([]);
github josdejong / mathjs / examples / advanced / web_server / server.js View on Github external
function formatError (err) {
  if (err instanceof workerpool.Promise.TimeoutError) {
    return 'TimeoutError: Evaluation exceeded maximum duration of ' + TIMEOUT / 1000 + ' seconds';
  }
  else {
    return err.toString();
  }
}
github leancloud / leanmessage-demo / server / index.js View on Github external
function formatError(err) {
  if (err instanceof workerpool.Promise.TimeoutError) {
    return 'TimeoutError: Evaluation exceeded maximum duration of ' + TIMEOUT / 1000 + ' seconds';
  } else {
    return err.toString();
  }
}
github CodeChain-io / codechain-indexer / src / models / logic / utils / workerpool.ts View on Github external
return PlatformAddress.fromPublic(pubKey, {
                    networkId: tx.unsigned.networkId()
                }).toString();
            })
        );
    }

    const pool = workerpool.pool({
        nodeWorker: "auto"
    } as any);
    const networkId = txs[0].unsigned.networkId();
    const signatureAndMessages = txs.map(tx => ({
        signature: tx.signature(),
        message: tx.unsigned.unsignedHash().toString()
    }));
    const signerPubKeys: string[][] = (await workerpool.Promise.all(
        _.chunk(signatureAndMessages, 100).map(chunk => {
            return pool.exec(getSignerPublicsFromSignatures, [chunk]);
        })
    )) as any;
    const regularKeyOwnerAndPubKeys: [
        string | null,
        string
    ][][] = await Promise.all(
        signerPubKeys.map(async (signerPubKey: string[]) => {
            return Promise.all(
                signerPubKey.map(
                    async (
                        signerPubKey: string
                    ): Promise<[string | null, string]> => {
                        const regularKeyOwner = await getRegularKeyOwnerByPublicKey(
                            signerPubKey,

workerpool

Offload tasks to a pool of workers on node.js and in the browser

Apache-2.0
Latest version published 28 days ago

Package Health Score

91 / 100
Full package analysis