Skip to content
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

Change Promises to Async/Await #3584

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jmk89
Copy link
Contributor

@jmk89 jmk89 commented Sep 4, 2022

Some were simple and some were not

@github-actions
Copy link

github-actions bot commented Sep 4, 2022

Binder 👈 Launch a binder notebook on branch jmk89/ipywidgets/promisetoasync

@jmk89
Copy link
Contributor Author

jmk89 commented Sep 4, 2022

This is a replacement to #2779

@jmk89 jmk89 changed the title Promisetoasync Change Promises to Async/Await Sep 4, 2022
@jasongrout jasongrout requested a review from ibdafna September 20, 2022 17:08
@jasongrout jasongrout added this to the 8.1 milestone Sep 27, 2022
@maartenbreddels
Copy link
Member

I wonder what this means for performance (having skimmed over https://v8.dev/blog/fast-async ).
I might do a comparison before/after to see if it does matter.

@jmk89
Copy link
Contributor Author

jmk89 commented Sep 28, 2022

Having some trouble figuring out what to do about the failing checks. Particularly I can't replicate the Error: src/widget.ts(289,5): error TS2322: Type 'Dict<unknown>' is not assignable to type 'Dict<BufferJSON>'. on my local machine when I run ./dev-install.sh or a clean/build.

The build error is happening in a method I refactored out of _handle_comm_msg. It's nearly a copy and paste of the original promise callback function. Any advice is welcome.

@ibdafna
Copy link
Member

ibdafna commented Sep 28, 2022

@jmk89 This is due to the change in the this context. I will add a suggestion shortly

@ibdafna
Copy link
Member

ibdafna commented Oct 11, 2022

@jmk89 Here is a commit I added last week to fix the issue of not compiling: ibdafna@c4f468e

@jasongrout
Copy link
Member

As an update, we discussed this in the ipywidgets dev meeting, and a few of us will have more time to look at this next week during the widgets dev workshop. Thanks!

@ibdafna
Copy link
Member

ibdafna commented Oct 11, 2022

@jmk89 I am happy to push the fix above, directly to this branch, with your permission! 🙏

@jmk89
Copy link
Contributor Author

jmk89 commented Oct 14, 2022

@ibdafna sounds good to me, thanks for asking 😄 . Although I'm not fully understanding the fix 😅 - it seems to me like setting the state_change to the awaited state_change breaks the "chain of state change" which was being queued.

It's quite likely that I'm misunderstanding, if there's any enlightenment you can forward my way I'd appreciate it 😄

Copy link
Contributor

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

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

I'm not entirely convinced we should be changing the signature of public methods from sync to async and not awaiting on them.
We could inadvertently be introducing a lot of race conditions because previously we didn't await on promises and now we're awaiting on them.

Copy link
Contributor Author

@jmk89 jmk89 left a comment

Choose a reason for hiding this comment

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

@DonJayamanne thanks for taking the time to look through my PR and leave feedback. I was initially painting with some broad strokes here.

packages/base/src/widget.ts Outdated Show resolved Hide resolved
packages/base-manager/src/manager-base.ts Outdated Show resolved Hide resolved
packages/base/src/viewlist.ts Outdated Show resolved Hide resolved
Copy link
Contributor Author

@jmk89 jmk89 left a comment

Choose a reason for hiding this comment

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

Updated some methods from @DonJayamanne feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants