eventloop_async_blocking.js

PHOTO EMBED

Thu Jan 28 2021 07:31:51 GMT+0000 (Coordinated Universal Time)

Saved by @noobj

fastify.get('/async-block-event-loop', async (_request, reply) => {
  const hash = crypto.createHash('sha256');
  const numberOfHasUpdates = 10e6;

  const updatehashAsync = async () => {
    hash.update(randomString());
  };

  for (let iter = 0; iter < numberOfHasUpdates; iter++) {
    await updatehashAsync();
  }
  reply.send({ data: 'Finished long process' });
});
content_copyCOPY