Skip to content

Comparisons

Compare ciorent usage with other concurrency libraries.

Stream files sequentially to output.

import { mutex } from 'ciorent';
import { streamToOutput, streamFile } from './output.ts';
const mu = mutex.init();
for (let i = 0; i < 5; i++)
mutex.run(mu, streamToOutput, streamFile(i));

Read file content and return the hashes, need to limit concurrent file reads to avoid issues such as too many file handles.

import { readFile, hash } from './file.ts';
import { semaphore } from 'ciorent';
const getHash = async (path: string) => hash(await readFile(path));
export const getHashes = (paths: string[]) => {
// No limit when not needed
if (paths.length < 10) return Promise.all(paths.map(getHash));
const sem = semaphore.init(10, paths.length - 10);
return Promise.all(
paths.map((path) => semaphore.run(sem, getHash, path))
);
}