29 lines
539 B
Go
29 lines
539 B
Go
/*
|
|||
|
|
* Copyright (c) 2025 Beijing Hardman Automation Equipment Co., LTD. All rights reserved.
|
||
|
|
*
|
||
|
|
* Project: adapter
|
||
|
|
* File: utils.go
|
||
|
|
* Last: 2025-05-11 23:27:50
|
||
|
|
* Author: wangcheng@bj-hardman.com
|
||
|
|
*/
|
||
|
|
|
||
|
|
package robot
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// sleepWithContext 辅助函数:带上下文感知的休眠
|
||
|
|
func sleepWithContext(ctx context.Context, duration time.Duration) error {
|
||
|
|
timer := time.NewTimer(duration)
|
||
|
|
defer timer.Stop()
|
||
|
|
|
||
|
|
select {
|
||
|
|
case <-ctx.Done():
|
||
|
|
return ctx.Err()
|
||
|
|
case <-timer.C:
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
}
|