Golang:转向窗罩

I want to operate my window coverings with my smartphone. Now every time I change the position on my phone a method

func main() {
OnUpdate(func(tPos int) {
     wc(tPos,cPos)
     cPos = tPos
  }
}

is called where tPos is an integer between 0 and 100 which is is target position. There also is a variable for the current position cPos. OnUpdate should call a function which either open or closes the window covering depending of the order relation between cPos and tPos. This function looks like this.

func wc(tPos int, cPos int){
    switch{
        case tPos == 0:
            log.Println("close")
        case tPos == 100:
            log.Println("open")
        case tPos > cPos:
            t := time.Duration( (tPos - cPos)*10*openTime)
            log.Println("open")
            time.Sleep( t  * time.Millisecond)
            log.Println("stop")
        case tPos < cPos:
            t := time.Duration( (cPos - tPos)*10*closeTime)
            log.Println("close")
            time.Sleep( t  * time.Millisecond)
            log.Println("stop")
    }
}

My problem now is that there should be some delay. I want that after OnUpdate is called there is a timer for like 3 seconds and then wc is called unless OnUpdate is called again during that 3 seconds.

But I don't know how to do this. Can someone tell me what is a good way to do that?

Not completely sure about your meaning, but I'll give it a go anyway. What calls OnUpdate? Is that on you phone? Do you simply want to sleep before calling wc inside the callback you provide to OnUpdate?

With that in mind please have a look at : https://play.golang.org/p/4vVpEEUcqg

My understanding is that you want make sure wc is not called too often. The for/select statements in run makes sure that wc is only called once every 3 seconds at most.