Allow asynchronous callback functions in filter.

This commit is contained in:
David Braun 2018-08-27 16:40:01 -04:00
parent cd1a4a4e96
commit cdfb4655b5
No known key found for this signature in database
GPG key ID: 87EC41ADF710B7E2
2 changed files with 7 additions and 9 deletions

View file

@ -161,17 +161,15 @@ const Channel = function(length = 0) {
filter: (callbackfn, thisArg) => {
const output = Channel();
(async () => {
for (;;) {
const value = await readOnly.shift();
if (value === undefined) {
await output.close();
break;
} else if (callbackfn.call(thisArg, value)) {
(async () => {
await readOnly.forEach(async value => {
if (await callbackfn.call(thisArg, value)) {
await output.push(value);
}
}
});
await output.close();
})();
return output;