Skip to content

Commit 5bad6cf

Browse files
authored
Implements getQuickJSImmediate (bellard#16)
* Implements getQuickJSImmediate * Update quickjs.ts * Prettier
1 parent 0e14208 commit 5bad6cf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ The root entrypoint of this library is the `getQuickJS` function, which returns
4141
a promise that resolves to a [QuickJS singleton](doc/classes/quickjs.md) when
4242
the Emscripten WASM module is ready.
4343

44+
Once `getQuickJS` has been awaited at least once, you also can use the `getQuickJSImmediate`
45+
function to directly access the singleton engine in your synchronous code.
46+
4447
### Safely evaluate Javascript code
4548

4649
See [QuickJS.evalCode](https://github.com/justjake/quickjs-emscripten/blob/master/doc/classes/quickjs.md#evalcode)

ts/quickjs.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,14 @@ export async function getQuickJS(): Promise<QuickJS> {
984984
}
985985
return singleton
986986
}
987+
988+
/**
989+
* This is the top-level entrypoint for the quickjs-emscripten library.
990+
* Get the root QuickJS API.
991+
*/
992+
export function getQuickJSImmediate(): QuickJS {
993+
if (!singleton) {
994+
throw new Error('QuickJS not initialized. Either wait for `ready` or use getQuickJS()')
995+
}
996+
return singleton
997+
}

0 commit comments

Comments
 (0)