Make some callbacks failable and add error handling

This commit is contained in:
Leonid Logvinov
2018-01-10 13:51:09 +01:00
parent 065570ebf5
commit 292c3bbff8
9 changed files with 88 additions and 60 deletions

View File

@@ -25,7 +25,7 @@ export const reportNoErrorCallbackErrors = (done: DoneCallback, expectToBeCalled
};
};
export const reportNodeCallbackErrors = (done: DoneCallback) => {
export const reportNodeCallbackErrors = (done: DoneCallback, expectToBeCalledOnce = true) => {
return <T>(f?: (value: T) => void) => {
const wrapped = (error: Error | null, value: T | undefined) => {
if (!_.isNull(error)) {
@@ -37,7 +37,9 @@ export const reportNodeCallbackErrors = (done: DoneCallback) => {
}
try {
f(value as T);
done();
if (expectToBeCalledOnce) {
done();
}
} catch (err) {
done(err);
}