-
Notifications
You must be signed in to change notification settings - Fork 96
Espruino.Core.Serial.getPorts
can callback too early
#194
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
Comments
Do you know why the original code isn't working?
Seemed pretty clear-cut to me? Unless one of the serial implementations is calling
Surely this should be some issue in the node_serialport implementation? The idea is that we will return whatever ports we can almost immediately as some users were getting fed up we were for instance waiting for Bluetooth devices when they just wanted to connect to serial and it was right there - but the handling for that (returning the ports as/when available and using shouldCallAgain) should be in each implementation? |
Oooh that's good context, maybe I should dig further into the cause then, I'll add some debugging into callbacks and see what hits. I'd never seen this happen anywhere else to be fair, on my Mac etc. I do get ports back, but for whatever reason on my Linux machine I was always getting empty sets of ports back from the callback on |
Thanks! Worst case you could grab an ESP32 devkit or similar - they're usually only $5 or so |
I've got an STM32 dev kit and an ESP32 dev kit, but I have also just ordered a Pixl.JS and an Espruino WiFi too to add to the collection 😄 I'll do some more digging on this either way rather than changing everything in case it's an issue elsewhere. |
Alright got time to investigate this further and I've tracked down the issue I think. The early callback is indeed one of the implementations calling the callback twice, it's the In my case I hit an error on My patch in #195 works just because that changes the behavior in a way that rather than waiting for I'll push a fix for the actual issue now. Is there any benefit in changing to a promises type thing like I did in #195 or shall I drop that one and just fix the current issue? |
Great - thanks for looking into this and getting that fix done! I'm all for moving to a promise-based solution (as given what just happened it seems more stable). However I'm not sure I understand why you're having to use The serial endpoints should all call |
I think originally I was thinking I'd have some reporting or logging if any rejected but I think I guess I could also wrap each promise in the |
Thanks - Promise.race inside would be quite tidy. I think for now I wouldn't worry though - just the Promise.all would tidy things up nicely, and it doesn't do timeouts at the moment (and we haven't needed it to date) so maybe it's best not to complicate it. In some ways it's better if it 'just breaks' and someone reports it rather than it breaking silently and taking 5s to get ports each time. |
So I suppose the downside of I just took delivery of my Pico and Pixl.js boards too so I'll try this with all the Espruino boards I have hooked up 😄 |
Yes, that sounds good to me. Because we're just using callbacks, not Promises, I can't think we'd really end up doing any rejection (and if we ever did to that could just be caught and turned into an error + resolve with no ports?) |
Sounds good to me yeah. I've updated #195 with the latest code 👌🏻 |
I've been trying to track down why
Espruino.Core.Serial.getPorts
was not returning local serial devices on my system (Arch Linux). What I discovered was thatcallback
was being called beforeports
is being fully populated, even calling again withshouldCallAgain
it appears to be actually a race condition, the ports are being returned by the device but not until after the callback is hit.The text was updated successfully, but these errors were encountered: