Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Major API change on JSClosure #113

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
kateinoigakukun merged 11 commits into main from katei/update-jsclosure
Jan 4, 2021
Merged

Major API change on JSClosure #113

kateinoigakukun merged 11 commits into main from katei/update-jsclosure
Jan 4, 2021

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jan 2, 2021
edited
Loading

Motivation

While integrating async/await feature, I found JSPromise has too complex API. (e.g. too many overloads, unsafe generic parameters, and lifetime management)
So I want to refine the API before async/await integration. As a first step, I changed JSClosure API.

Changes

  • Add JSOneshotClosure which provides an ability to invoke a closure at most once. This will be suitable to use with functions like Promise.then
  • Remove JSClosure.init(_ body: @escaping ([JSValue]) -> Void) overload, which forces users to write result type in closure.
  • Add JSClosure lifetime test suites

- Add `JSOneshotClosure` which provide an ability to invoke a closure
 at most once.
- Remove `JSClosure.init(_ body: @escaping ([JSValue]) -> Void)`
 overload, which forces users to write result type in closure.
- Add JSClosure lifetime test suites
Copy link

github-actions bot commented Jan 2, 2021
edited
Loading

Time Change: -525.25ms (6%) ✅

Total Time: 8,162ms

Test name Duration Change
Serialization/Write JavaScript number directly 145.75ms -18.5ms (12%) 👏
Serialization/Write JavaScript string directly 154.5ms -10ms (6%)
Serialization/Swift Int to JavaScript 2,602.5ms -188.25ms (7%)
Serialization/Swift String to JavaScript 2,665.25ms -179ms (6%)
i️ View Unchanged
Test name Duration Change
Object heap/Increment and decrement RC 2,594ms -129.5ms (4%)

performance-action

Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this seems legit with a few suggestions in comments.

Copy link
Member

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about that JSClosure.init overload myself when I introduced, but you're right it brings more harm than good. Also, great idea to simplify a lot of things with JSOneshotClosure! 👍

kateinoigakukun reacted with laugh emoji
@MaxDesiatov MaxDesiatov requested a review from a team January 2, 2021 17:07
Copy link
Member Author

@swiftwasm/jskit-team Could anyone review this change? I want two or more approvals for this kind of API change before merging 🙏

Copy link
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at a desktop now. LGTM except for these things

Copy link
Member Author

@j-f1 I addressed reviewed points. Could you take a look again?

Comment on lines +506 to +509
timeout = JSTimer(millisecondsDelay: timeoutMilliseconds, isRepeating: false) {
fatalError("timer should be cancelled")
}
timeout = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally happy to punt this to another issue, but since there isn’t necessarily a need to cancel a setTimeout, could there be an API that doesn’t require holding the JSTimer instance? I guess users could just do

JSObject.global.setTimeout(JSOneshotClosure {
 // ...
 return undefined
}, 1000)

Copy link
Member Author

@kateinoigakukun kateinoigakukun Jan 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can provide such API in this signature for example.

JSTimer.timeout(millisecondsDelay: 100) {
 // ...
}

This PR is already too large, so let's implement it in another PR 👍

j-f1 reacted with thumbs up emoji
Copy link
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol oops accounts are hard

kateinoigakukun reacted with hooray emoji
@kateinoigakukun kateinoigakukun deleted the katei/update-jsclosure branch January 4, 2021 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@MaxDesiatov MaxDesiatov MaxDesiatov approved these changes

@j-f1 j-f1 j-f1 approved these changes

+1 more reviewer

@jed-fox-neeva jed-fox-neeva jed-fox-neeva approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /