Skip to content

Expose UnsafeEventLoopYield by property #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Plugins/PackageToJS/Templates/runtime.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
type ref = number;
type pointer = number;

declare class Memory {
readonly rawMemory: WebAssembly.Memory;
private readonly heap;
Expand All @@ -18,9 +21,6 @@ declare class Memory {
writeFloat64: (ptr: pointer, value: number) => void;
}

type ref = number;
type pointer = number;

/**
* A thread channel is a set of functions that are used to communicate between
* the main thread and the worker thread. The main thread and the worker thread
Expand Down Expand Up @@ -189,6 +189,7 @@ declare class SwiftRuntime {
private textEncoder;
/** The thread ID of the current thread. */
private tid;
UnsafeEventLoopYield: typeof UnsafeEventLoopYield;
constructor(options?: SwiftRuntimeOptions);
setInstance(instance: WebAssembly.Instance): void;
main(): void;
Expand All @@ -209,6 +210,8 @@ declare class SwiftRuntime {
private postMessageToMainThread;
private postMessageToWorkerThread;
}
declare class UnsafeEventLoopYield extends Error {
}

export { SwiftRuntime };
export type { SwiftRuntimeOptions, SwiftRuntimeThreadChannel };
1 change: 1 addition & 0 deletions Plugins/PackageToJS/Templates/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
this.version = 708;
this.textDecoder = new TextDecoder("utf-8");
this.textEncoder = new TextEncoder(); // Only support utf-8
this.UnsafeEventLoopYield = UnsafeEventLoopYield;
/** @deprecated Use `wasmImports` instead */
this.importObjects = () => this.wasmImports;
this._instance = null;
Expand Down
1 change: 1 addition & 0 deletions Plugins/PackageToJS/Templates/runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class SwiftRuntime {
this.version = 708;
this.textDecoder = new TextDecoder("utf-8");
this.textEncoder = new TextEncoder(); // Only support utf-8
this.UnsafeEventLoopYield = UnsafeEventLoopYield;
/** @deprecated Use `wasmImports` instead */
this.importObjects = () => this.wasmImports;
this._instance = null;
Expand Down
4 changes: 3 additions & 1 deletion Runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class SwiftRuntime {
/** The thread ID of the current thread. */
private tid: number | null;

UnsafeEventLoopYield = UnsafeEventLoopYield;

constructor(options?: SwiftRuntimeOptions) {
this._instance = null;
this._memory = null;
Expand Down Expand Up @@ -749,4 +751,4 @@ export class SwiftRuntime {
/// This error is thrown to unwind the call stack of the Swift program and return the control to
/// the JavaScript side. Otherwise, the `swift_task_asyncMainDrainQueue` ends up with `abort()`
/// because the event loop expects `exit()` call before the end of the event loop.
export class UnsafeEventLoopYield extends Error {}
class UnsafeEventLoopYield extends Error {}