]> 127.0.0.1 Git - part/.git/commitdiff
update v0.24.6
authorqydysky <qydysky@foxmail.com>
Sat, 8 Apr 2023 13:20:53 +0000 (21:20 +0800)
committerqydysky <qydysky@foxmail.com>
Sat, 8 Apr 2023 13:20:53 +0000 (21:20 +0800)
funcCtrl/FuncCtrl.go
funcCtrl/FuncCtrl_test.go

index 7648c45cdd970ba2f8e8c712a293675a28da562e..53c68c84630f0bb5d1c575d7dffd061ea3ffe93e 100644 (file)
@@ -24,16 +24,13 @@ func (t *SkipFunc) UnSet() {
 // 新的替换旧的
 type FlashFunc struct {
        b atomic.Uintptr
+       l sync.Mutex
        c *context.CancelFunc
 }
 
 func (t *FlashFunc) Flash() (current uintptr) {
        current = uintptr(unsafe.Pointer(&struct{}{}))
        t.b.Store(current)
-       if t.c != nil {
-               (*t.c)()
-               t.c = nil
-       }
        return
 }
 
@@ -43,9 +40,10 @@ func (t *FlashFunc) NeedExit(current uintptr) bool {
        return t.b.Load() != current
 }
 
-func (t *FlashFunc) FlashWithContext() (current uintptr, c context.Context) {
-       current = uintptr(unsafe.Pointer(&struct{}{}))
-       t.b.Store(current)
+func (t *FlashFunc) FlashWithContext() (c context.Context) {
+       t.l.Lock()
+       defer t.l.Unlock()
+
        if t.c != nil {
                (*t.c)()
                t.c = nil
index 6d7a4f5cc6cdb30e9dd640eda3dfcb5ac4775bc8..eb7d4259f15c9395d248f6cbb9d5ed9af0e360bc 100644 (file)
@@ -48,7 +48,7 @@ func Test_FlashFunc2(t *testing.T) {
        var cc = make(chan int, 2)
        var b FlashFunc
        var a = func(i int) {
-               _, c := b.FlashWithContext()
+               c := b.FlashWithContext()
                <-c.Done()
                cc <- i
        }