1.0.4 • Published 2 years ago

@elioenaiferrari/bolt v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Bolt

  • Studies to work with concurrency

Examples

  • caller
const Bolt = require('@elioenaiferrari@/bolt');

// YES! use relative path based in you workspace path
const workerFile = 'src/send-mail.js';
// YES! is array (ever)
const dataToSend = [1, 2, 3, 4];

Bolt.run(workerFile, dataToSend, {
  concurrency: 2,
  onMessage: (chunk) => {},
  onError: (error) => {},
  onClose: () => {},
  onDone: () => {},
});
  • receiver
const Bolt = require('@elioenaiferrari@/bolt');

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const sendMail = async (chunk = []) => {
  for (const user of chunk) {
    await sleep(1000);
    process.send(`Sending email to ${user.email}`);
  }
};

// !IMPORTANT
Bolt.listen(sendMail);
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago