Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork57
Add Asyncify support#107
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
yonihemi wants to merge12 commits intoswiftwasm:mainChoose a base branch fromyonihemi:asyncify
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
d3b0a4c Implement sleep
yonihemi62953b7 Add Promise sync handlers
yonihemi074467d Add Promise sync handlers
yonihemi3ae49b6 Update index.ts
yonihemiccb7297 Correctly allocate buffer for Asyncify stack
yonihemia3dcfa7 Merge remote-tracking branch 'upstream/main' into asyncify
yonihemi8704225 Merge remote-tracking branch 'upstream/main' into asyncify
yonihemid1fff95 For incoming function calls while instance is sleeping, process after…
yonihemi2def067 Remove await with timeout to simplify runtime interface
yonihemia733efb Merge remote-tracking branch 'upstream/main' into asyncify
yonihemibcfa3cb Use new simplified JSPromise API
yonihemicd302ce Defer resuming after caught rejected Promise
yonihemiFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
130 changes: 129 additions & 1 deletionRuntime/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletionsSources/JavaScriptKit/PauseExecution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import _CJavaScriptKit | ||
| /// Unwind Wasm module execution stack and rewind it after specified milliseconds, | ||
| /// allowing JavaScript events to continue to be processed. | ||
| /// **Important**: Wasm module must be [asyncified](https://emscripten.org/docs/porting/asyncify.html), | ||
| /// otherwise JavaScriptKit's runtime will throw an exception. | ||
| public func pauseExecution(milliseconds: Int32) { | ||
| _sleep(milliseconds) | ||
| } | ||
| extension JSPromise { | ||
| /// Unwind Wasm module execution stack and rewind it after promise resolves, | ||
| /// allowing JavaScript events to continue to be processed in the meantime. | ||
| /// - Parameters: | ||
| /// - timeout: If provided, method will return a failure if promise cannot resolve | ||
| /// before timeout is reached. | ||
| /// | ||
| /// **Important**: Wasm module must be [asyncified](https://emscripten.org/docs/porting/asyncify.html), | ||
| /// otherwise JavaScriptKit's runtime will throw an exception. | ||
| public func syncAwait() -> Result<JSValue, JSValue> { | ||
| var kindAndFlags = JavaScriptValueKindAndFlags() | ||
| var payload1 = JavaScriptPayload1() | ||
| var payload2 = JavaScriptPayload2() | ||
| _syncAwait(jsObject.id, &kindAndFlags, &payload1, &payload2) | ||
| let result = RawJSValue(kind: kindAndFlags.kind, payload1: payload1, payload2: payload2).jsValue() | ||
| if kindAndFlags.isException { | ||
| return .failure(result) | ||
| } else { | ||
| return .success(result) | ||
| } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletionsSources/JavaScriptKit/XcodeSupport.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionsSources/_CJavaScriptKit/_CJavaScriptKit.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletionsSources/_CJavaScriptKit/include/_CJavaScriptKit.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.