swc/bundler/tests/.cache/untrusted/78a6fdc3bfde2a08a672858a2061b1659f7fa597.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

32 lines
659 B
TypeScript

// Loaded from https://raw.githubusercontent.com/denjucks/dex/master/lib/util/timeout.js
export class KnexTimeoutError extends Error {
constructor(message) {
super(message);
this.name = 'KnexTimeoutError';
}
}
export function timeout(promise, ms) {
return new Promise(function (resolve, reject) {
const id = setTimeout(function () {
reject(new KnexTimeoutError('operation timed out'));
}, ms);
function wrappedResolve(value) {
clearTimeout(id);
resolve(value);
}
function wrappedReject(err) {
clearTimeout(id);
reject(err);
}
promise.then(wrappedResolve, wrappedReject);
});
}