penpal
Version:
A promise-based library for communicating with iframes via postMessage.
30 lines (24 loc) • 667 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _enums = require("./enums");
/**
* Starts a timeout and calls the callback with an error
* if the timeout completes before the stop function is called.
*/
var _default = (timeout, callback) => {
let timeoutId;
if (timeout !== undefined) {
timeoutId = window.setTimeout(() => {
const error = new Error("Connection timed out after ".concat(timeout, "ms"));
error.code = _enums.ErrorCode.ConnectionTimeout;
callback(error);
}, timeout);
}
return () => {
clearTimeout(timeoutId);
};
};
exports.default = _default;
;