diff --git a/Build/lib/cache-filesystem.ts b/Build/lib/cache-filesystem.ts index bfdb1e2e..40b6ccb9 100644 --- a/Build/lib/cache-filesystem.ts +++ b/Build/lib/cache-filesystem.ts @@ -6,6 +6,7 @@ import { mkdirSync } from 'fs'; import picocolors from 'picocolors'; import { fastStringArrayJoin } from './misc'; import { peek } from 'bun'; +import { performance } from 'perf_hooks'; const identity = (x: any) => x; @@ -78,7 +79,7 @@ export class Cache { tableName = 'cache', type }: CacheOptions = {}) { - const start = Bun.nanoseconds(); + const start = performance.now(); this.cachePath = cachePath; mkdirSync(this.cachePath, { recursive: true }); @@ -120,7 +121,7 @@ export class Cache { this.db.exec('VACUUM;'); } - const end = Bun.nanoseconds(); + const end = performance.now(); console.log(`${picocolors.gray(`[${((end - start) / 1e6).toFixed(3)}ms]`)} cache initialized from ${this.cachePath}`); } diff --git a/Build/lib/fetch-assets.ts b/Build/lib/fetch-assets.ts index 81debfb2..32a2dd5a 100644 --- a/Build/lib/fetch-assets.ts +++ b/Build/lib/fetch-assets.ts @@ -1,5 +1,6 @@ import picocolors from 'picocolors'; import { defaultRequestInit, fetchWithRetry } from './fetch-retry'; +import { setTimeout } from 'timers/promises'; class CustomAbortError extends Error { public readonly name = 'AbortError'; @@ -15,7 +16,7 @@ const sleepWithAbort = (ms: number, signal: AbortSignal) => new Promise((r function stop(this: AbortSignal) { reject(this.reason as Error); } signal.addEventListener('abort', stop, { once: true }); - Bun.sleep(ms).then(resolve).catch(reject).finally(() => signal.removeEventListener('abort', stop)); + setTimeout(ms, undefined, { ref: false }).then(resolve).catch(reject).finally(() => signal.removeEventListener('abort', stop)); }); export async function fetchAssets(url: string, fallbackUrls: string[] | readonly string[]) { diff --git a/Build/lib/fetch-retry.ts b/Build/lib/fetch-retry.ts index 1c475152..afee348f 100644 --- a/Build/lib/fetch-retry.ts +++ b/Build/lib/fetch-retry.ts @@ -1,5 +1,6 @@ import retry from 'async-retry'; import picocolors from 'picocolors'; +import { setTimeout } from 'timers/promises'; // retry settings const MIN_TIMEOUT = 10; @@ -84,7 +85,7 @@ function createFetchRetry($fetch: typeof fetch): FetchWithRetry { if (retryAfter > retryOpts.maxRetryAfter) { return res; } - await Bun.sleep(retryAfter * 1e3); + await setTimeout(retryAfter * 1e3, undefined, { ref: false }); } } throw new ResponseError(res); diff --git a/Build/trace/index.ts b/Build/trace/index.ts index 48f71d11..dac69c49 100644 --- a/Build/trace/index.ts +++ b/Build/trace/index.ts @@ -4,8 +4,6 @@ import picocolors from 'picocolors'; const SPAN_STATUS_START = 0; const SPAN_STATUS_END = 1; -const NUM_OF_MS_IN_NANOSEC = 1_000_000; - const spanTag = Symbol('span'); export interface TraceResult { @@ -36,7 +34,7 @@ export interface Span { } export const createSpan = (name: string, parentTraceResult?: TraceResult): Span => { - const start = Bun.nanoseconds(); + const start = performance.now(); let curTraceResult: TraceResult; @@ -45,7 +43,7 @@ export const createSpan = (name: string, parentTraceResult?: TraceResult): Span } else { curTraceResult = { name, - start: start / NUM_OF_MS_IN_NANOSEC, + start, end: 0, children: [] }; @@ -58,9 +56,9 @@ export const createSpan = (name: string, parentTraceResult?: TraceResult): Span if (status === SPAN_STATUS_END) { throw new Error(`span already stopped: ${name}`); } - const end = time ?? Bun.nanoseconds(); + const end = time ?? performance.now(); - curTraceResult.end = end / NUM_OF_MS_IN_NANOSEC; + curTraceResult.end = end; status = SPAN_STATUS_END; };