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

Add removeListener for event emitter #34

Open
cderv opened this issue Mar 10, 2019 · 0 comments
Open

Add removeListener for event emitter #34

cderv opened this issue Mar 10, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@cderv
Copy link
Collaborator

cderv commented Mar 10, 2019

All the function for an event emitter object has not yet be implemented. Especially, removeListener.
See spec: https://nodejs.org/api/events.html#events_emitter_removelistener_eventname_listener

it is included in once() because the listener is removed at first occurrence. But when register with on(), there is no way yet to remove the listener.

Easy way :

Consider one listener per event only. Removing the listener is equivalent to removing the event.

Hard way:

Consider several listeners per event. removeListener should be able to remove the correct listener.

Ideas:

  • Currently callbacks objects return a rm function at registration.
  • This function could be kept somewhere (in a list or env) and called when needed to remove the listener.
  • This would require a key so that the correct listener is removed. 🤔 use digest::digest() ?

examples

myEmitter <- EventEmitter$new()
myEmitter$on('event',
    function() {
        message("an event occured")
    }
)

how to remove this listener with anonymous function ?

  • myEmitter$removeListener('event", function() { message("an event occured") }) ?

Only allow it with named function?

myEmitter <- EventEmitter$new()
my_fun <-  function() {
        message("an event occured")
    }
myEmitter$on('event', my_fun)
  • myEmitter$removeListener('event', "myfun") ?
  • myEmitter$removeListener('event', myfun) ?
@cderv cderv added the enhancement New feature or request label Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant