EEBus: abort run loop and limit assertion on context cancellation (#32494)
This commit is contained in:
parent
4a878838e7
commit
fed3fb731c
8 changed files with 54 additions and 12 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package eebus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
|
@ -52,10 +53,11 @@ const limitTimeout = 50 * time.Second
|
|||
|
||||
// AssertLimit states the current limit to a newly available Controllable System
|
||||
// ([LPC-913]/[LPP-913]). Blocks while retrying- the CS ignores writes that do not
|
||||
// follow a heartbeat and may reject them while still in state "init".
|
||||
func AssertLimit(log *util.Logger, write func() error) {
|
||||
// follow a heartbeat and may reject them while still in state "init". Retrying
|
||||
// stops when ctx is cancelled, i.e. when the device is gone.
|
||||
func AssertLimit(ctx context.Context, log *util.Logger, write func() error) {
|
||||
bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(limitTimeout))
|
||||
if err := backoff.Retry(write, bo); err != nil {
|
||||
if err := backoff.Retry(write, backoff.WithContext(bo, ctx)); err != nil && ctx.Err() == nil {
|
||||
log.DEBUG.Printf("assert limit: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue