等待插卡逻辑完成
This commit is contained in:
@@ -26,7 +26,7 @@ func PushCard(ctx context.Context) leaf.HandlerFunc {
|
||||
devices := make([]*card_device.Device, 0)
|
||||
for _, group := range config.C.Game.CardGroups {
|
||||
gv, _ := json.Marshal(group)
|
||||
zap.S().Info("发卡指针初始化:", string(gv))
|
||||
zap.S().Info("发卡器指针:", string(gv))
|
||||
|
||||
device, err := card_device.New(group)
|
||||
if err != nil {
|
||||
|
||||
43
internal/routes/play/wait_card.go
Normal file
43
internal/routes/play/wait_card.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package play
|
||||
|
||||
import (
|
||||
"game-driver/internal/middleware"
|
||||
"game-driver/internal/schema"
|
||||
"game-driver/leaf"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func WaitCard(c *leaf.Context) {
|
||||
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
||||
|
||||
var waitCard time.Duration
|
||||
if a, ok := payload.Game["wait_card"]; ok {
|
||||
if v, ok := a.(float64); ok {
|
||||
waitCard = time.Duration(v)
|
||||
}
|
||||
}
|
||||
|
||||
// 等待组
|
||||
var wait sync.WaitGroup
|
||||
defer wait.Wait()
|
||||
|
||||
a := make(chan string)
|
||||
defer close(a)
|
||||
|
||||
wait.Add(1)
|
||||
go func() {
|
||||
defer wait.Done()
|
||||
time.Sleep(3 * time.Second)
|
||||
a <- "卡片数据"
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-c.Done():
|
||||
case <-time.After(waitCard * time.Second):
|
||||
case _, ok := <-a: // 等待卡片插入
|
||||
if ok { // 非关闭信号
|
||||
Default(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user