redis-smq-common
Version:
RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.
18 lines • 518 B
JavaScript
import { AsyncCallbackTimeoutError } from './errors/index.js';
export function withTimeout(callback, timeoutMs) {
let called = false;
const timeoutId = setTimeout(() => {
if (called)
return;
called = true;
callback(new AsyncCallbackTimeoutError());
}, timeoutMs);
return (err, result) => {
if (called)
return;
called = true;
clearTimeout(timeoutId);
callback(err, result);
};
}
//# sourceMappingURL=with-timeout.js.map