h4yn0nnym0u5e
Well-known member
This is probably a question for Paul, so I hope he's got some bandwidth!
I've been making regular and successful use of EventResponder to perform what I understand to be its intended action, to trigger non-interrupt-safe code from within an interrupt. I my use cases it's typically audio-related, triggering events from within the audio update to cause stuff to happen as soon as yield() is called.
Despite having looked at the source fairly often, I never spotted until just now that one yield() processes just one triggered Event, no matter how many are pending; at least, that's the way it appears to me. I'd been expecting all pending events to be processed as soon as yield() is called, and it seems to me that logically this should be the case. The comments say "events are often triggered within interrupts or other timing sensitive code. EventResponder can call your function a short time later", but if it takes 10 iterations of loop() to process 10 events, there's a huge risk of the short time becoming very long indeed.
Seeking opinions on whether I'm (a) wrong about what the existing code does, (b) wrong to expect anything else, or (c) right and EventResponder needs updating... If it's important to preserve the existing action for legacy reasons, perhaps either a triggerNextYield() can be added (every event triggered this way is guaranteed response on the next yield() call), or a static flag could be added to switch between the existing single-response and new all-responses behaviour.
Happy to add the feature and submit a PR, if it'll help.
I've been making regular and successful use of EventResponder to perform what I understand to be its intended action, to trigger non-interrupt-safe code from within an interrupt. I my use cases it's typically audio-related, triggering events from within the audio update to cause stuff to happen as soon as yield() is called.
Despite having looked at the source fairly often, I never spotted until just now that one yield() processes just one triggered Event, no matter how many are pending; at least, that's the way it appears to me. I'd been expecting all pending events to be processed as soon as yield() is called, and it seems to me that logically this should be the case. The comments say "events are often triggered within interrupts or other timing sensitive code. EventResponder can call your function a short time later", but if it takes 10 iterations of loop() to process 10 events, there's a huge risk of the short time becoming very long indeed.
Seeking opinions on whether I'm (a) wrong about what the existing code does, (b) wrong to expect anything else, or (c) right and EventResponder needs updating... If it's important to preserve the existing action for legacy reasons, perhaps either a triggerNextYield() can be added (every event triggered this way is guaranteed response on the next yield() call), or a static flag could be added to switch between the existing single-response and new all-responses behaviour.
Happy to add the feature and submit a PR, if it'll help.