简体   繁体   中英

Kill a specific listener after the on has been fired

I have a node service that is running socket.io.

On top of this I have an event emitter to fire out updates based on user context. (eg context A has user 1, user 2, user 3, context B has user 4 & user 5)

When a successful connection to the socket has been made an event listener is registered to the context of the user.

                myEmitter.on(contextGuid, ()=>{
                    if(!socket.disconnected){
                        getUserListing();
                    }
                });

from this, I then fire context events outwards when I need to emit changes that have happened in the user's context group.

So the issue I have is more of a housekeeping problem. Is there a way to kill a specific listener on the emitter as they are all named the same thing (context guid) as I am currently spawning many listeners for each socket.

如果你想杀死一个监听器,只需使用与监听器初始化相同的语法,但在参数中输入 null!

myEmitter.on(null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM