You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
918 B
31 lines
918 B
2 years ago
|
import { g as getWorkerState } from './chunk-mock-date.a1c85759.js';
|
||
|
import { s as safeSetTimeout } from './chunk-utils-timers.52534f96.js';
|
||
|
|
||
|
const safeRandom = Math.random;
|
||
|
function withSafeTimers(fn) {
|
||
|
const currentSetTimeout = globalThis.setTimeout;
|
||
|
const currentRandom = globalThis.Math.random;
|
||
|
try {
|
||
|
globalThis.setTimeout = safeSetTimeout;
|
||
|
globalThis.Math.random = safeRandom;
|
||
|
const result = fn();
|
||
|
return result;
|
||
|
} finally {
|
||
|
globalThis.setTimeout = currentSetTimeout;
|
||
|
globalThis.Math.random = currentRandom;
|
||
|
}
|
||
|
}
|
||
|
const rpc = () => {
|
||
|
const { rpc: rpc2 } = getWorkerState();
|
||
|
return new Proxy(rpc2, {
|
||
|
get(target, p, handler) {
|
||
|
const sendCall = Reflect.get(target, p, handler);
|
||
|
const safeSendCall = (...args) => withSafeTimers(() => sendCall(...args));
|
||
|
safeSendCall.asEvent = sendCall.asEvent;
|
||
|
return safeSendCall;
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export { rpc as r };
|