Skip to content

Commit

Permalink
Use detectRuntime.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Jan 25, 2024
1 parent 83da27d commit 18447b0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/modelfusion/src/core/getRun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Run } from "./Run";
import { detectRuntime } from "../util/detectRuntime.js";
import { Run } from "./Run.js";

interface RunStorage {
getStore: () => Run | undefined;
Expand All @@ -8,20 +9,12 @@ interface RunStorage {
let runStorage: RunStorage | undefined;

async function ensureLoaded() {
// Note: using process[versions] instead of process.versions to avoid Next.js edge runtime warnings.
const versions = "versions";
const isNode =
typeof process !== "undefined" &&
process[versions] != null &&
process[versions].node != null;

if (!isNode) return Promise.resolve();

if (!runStorage) {
if (detectRuntime() === "node" && !runStorage) {
// Note: using "async_hooks" instead of "node:async_hooks" to avoid webpack fallback problems.
const { AsyncLocalStorage } = await import("async_hooks");
runStorage = new AsyncLocalStorage<Run>();
}

return Promise.resolve();
}

Expand Down

0 comments on commit 18447b0

Please sign in to comment.