Open lmcarreiro opened 5 years ago
Hey sorry for the late reply!
Currently that's not possible, but it could be a good idea for a new version of the module.
Anyway, since each method returns a Promise you can chain them like you'd do normally, using your example:
const { map, filter } = require('p-iteration');
const usersIds = [1, 2, 3];
const users = await map(usersIds, user => usergetById(id))
.then(users => filter(users, user => checkIsActive(user.anotherId)));
It's not so smooth though, for this case just going with sequential await
s is a bit simpler I think:
const users = await map(usersIds, user => usergetById(id));
const filteredUsers = await filter(users, user => checkIsActive(user.anotherId)));
It is common in libraries like this, to have a
chain
method, to allow you to use the methods in a chain without aux variables or putting one call inside the other.Example:
Is it possible to use an async chain?