Skip to content

Conversation

@kg
Copy link
Member

@kg kg commented Jul 16, 2021

Code does event listener management kind of ad-hoc right now, and this creates a lot of space for lifetime management or removal to get messed up. This is a draft of new APIs to simplify things and make it harder to make mistakes.

@ghost
Copy link

ghost commented Jul 16, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@kg kg added the arch-wasm WebAssembly architecture label Jul 16, 2021
@ghost
Copy link

ghost commented Jul 16, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Code does event listener management kind of ad-hoc right now, and this creates a lot of space for lifetime management or removal to get messed up. This is a draft of new APIs to simplify things and make it harder to make mistakes.

Author: kg
Assignees: -
Labels:

arch-wasm

Milestone: -

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

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

Nullable annotations appear to be wrong.

@kg kg force-pushed the eventlistenerapi branch from 49f1be6 to 6b7bc76 Compare July 21, 2021 03:06
@kg kg marked this pull request as ready for review July 21, 2021 11:01
@kg kg requested a review from marek-safar as a code owner July 21, 2021 11:01
@kg
Copy link
Member Author

kg commented Jul 21, 2021

I believe this is ready for review. The new design feels okay to me, and most importantly it's simple. I've been looping the websocket tests for about 10 hours now and they haven't failed yet.

@kg kg requested a review from vargaz July 24, 2021 16:35
return;
}
},
fireEvent: function (name, evt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test using the evt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could add one, but it's not really necessary since this API doesn't actually touch the event dispatch part

if (options?.Signal != null)
throw new NotImplementedException("EventListenerOptions.Signal");

var jsfunc = Runtime.GetWeakDelegateHandle(listener);
Copy link
Member

Choose a reason for hiding this comment

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

If we could wrap the listener with our own lambda here and call ReleaseInFlight(arg1) we would stop leaking inflight JSObjects of the event argument (which I introduced recently).

Copy link
Member Author

Choose a reason for hiding this comment

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

I will look into this, great idea

@pavelsavara
Copy link
Member

Please add test of registering same delegate to multiple event sources and it's unregistration.

@kg
Copy link
Member Author

kg commented Jul 27, 2021

Please add test of registering same delegate to multiple event sources and it's unregistration.

I did, it's called RegisterSameEventListener

@pavelsavara
Copy link
Member

Please add test of registering same delegate to multiple event sources and it's unregistration.

I did, it's called RegisterSameEventListener

That's same delegate twice into same source. I'm asking for same delegate into multiple source instances.

@kg kg merged commit a3ddef1 into dotnet:main Jul 28, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants