-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathffi-client.ts
More file actions
24 lines (19 loc) · 766 Bytes
/
Copy pathffi-client.ts
File metadata and controls
24 lines (19 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
import type * as ffiTypes from "@eserstack/ajan/ffi";
// Lazy FFI singleton — loaded once per process, reused for every shell exec call.
let _lib: ffiTypes.FFILibrary | null = null;
let _libPromise: Promise<void> | null = null;
export const ensureLib = (): Promise<void> => {
if (_libPromise === null) {
_libPromise = import("@eserstack/ajan/ffi")
.then((ffi) => ffi.loadEserAjan())
.then((lib) => {
_lib = lib;
})
.catch(() => {
// Native library unavailable — callers use cross-runtime process fallback.
});
}
return _libPromise;
};
export const getLib = (): ffiTypes.FFILibrary | null => _lib;