Remove try catch from provided functions, user handles errors
This commit is contained in:
@@ -9,23 +9,11 @@ export function filter<T>(
|
||||
return new Transform({
|
||||
...options,
|
||||
async transform(chunk: T, encoding?: any, callback?: any) {
|
||||
let isPromise = false;
|
||||
try {
|
||||
const result = predicate(chunk, encoding);
|
||||
isPromise = result instanceof Promise;
|
||||
if (!!(await result)) {
|
||||
callback(null, chunk);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} catch (err) {
|
||||
if (isPromise) {
|
||||
// Calling the callback asynchronously with an error wouldn't emit the error, so emit directly
|
||||
this.emit("error", err);
|
||||
callback();
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
const result = await predicate(chunk, encoding);
|
||||
if (result === true) {
|
||||
callback(null, chunk);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user