jfhbrook / pyee

A rough port of Node.js's EventEmitter to Python with a few tricks of its own
https://github.com/jfhbrook/public
MIT License
371 stars 39 forks source link

Fix race condition in once #77

Closed forslund closed 4 years ago

forslund commented 4 years ago

This is a naive locking approach to the issue reported in #76

This PR adds a check in the once-wrapper that listener method is still registered before removing. To ensure atomic execution a lock is added around removals of listeners.

forslund commented 4 years ago

Good comments all around will try to get an update done tonight / tomorrow

forslund commented 4 years ago

Good comments all around will try to get an update done tonight / tomorrow

jfhbrook commented 4 years ago

Cool! Any work you do on this is much appreciated, and if you run out of steam I can always take and run with your work.

forslund commented 4 years ago

The testcase became a bit more convoluted since the removal is done before the target function is called (I guess to minimize the risk of this kind of race). Let me know if the solution is too hacky.

forslund commented 4 years ago

I dropped the test commit from the branch and squashed the remaining two commits into a single one. should be good to go now.

jfhbrook commented 4 years ago

Released in 8.1.0. Thanks!