Thank Robin for your answer,
It may makes sense to not remove a listener that is currently executing, but I don't see how it is supposed to be done in practice. How can I call removeListener from outside the callback at the right moment (after wifi connected), without having a timer or another callback ? The example at http://microcosm.app/out/HSn2h is theorical, in practice you want to wait to receive the data before removing the listener (from inside the callback).
I tried what you suggest with no change, usin "wifi.removeListener("connected",f);" instead of "require("Wifi").removeListener("connected",f);".
I tried also like this :
This give time for the first callback calls round to happen (connected1 to connected4), but then again the call remove f function callback and all following callbacks. The process is not only halted, but callbacks get removed. I can see each callbacks left with
E.getSizeOf(global["\xFF"].modules.Wifi,3);
So next "connected" trigger only the first callback.
My workaround now is to manage myself my wifi listeners and subscribe only one callback, or else when I can I subscribe listeners in the reverse order I plan to unsubscribe them. But I am left with the feeling that something is wrong and I can't put the finger on it.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Thank Robin for your answer,
It may makes sense to not remove a listener that is currently executing, but I don't see how it is supposed to be done in practice. How can I call removeListener from outside the callback at the right moment (after wifi connected), without having a timer or another callback ? The example at http://microcosm.app/out/HSn2h is theorical, in practice you want to wait to receive the data before removing the listener (from inside the callback).
I tried what you suggest with no change, usin "wifi.removeListener("connected",f);" instead of "require("Wifi").removeListener("connected",f);".
I tried also like this :
This give time for the first callback calls round to happen (connected1 to connected4), but then again the call remove f function callback and all following callbacks. The process is not only halted, but callbacks get removed. I can see each callbacks left with
So next "connected" trigger only the first callback.
My workaround now is to manage myself my wifi listeners and subscribe only one callback, or else when I can I subscribe listeners in the reverse order I plan to unsubscribe them. But I am left with the feeling that something is wrong and I can't put the finger on it.
Sofyen