var store sync.Map gofunc(ctx context.Context) { for { select { case <-ctx.Done(): return // Mock ack get response ack case key := <-respAck: // Do something... v, ok := store.LoadAndDelete(key) if !ok { panic("not found value") } fmt.Printf("%#v", v) } } } funcSend(key string, value any) { // send to other nodes, net request // if send ok, record to map result := client.send(key, value) if result { store.Store(key, value) } }
var store sync.Map gofunc(ctx context.Context) { for { select { case <-ctx.Done(): return // Mock ack get response ack case key := <-respAck: // Do something... v, ok := store.LoadAndDelete(key) if !ok { panic("not found value") } fmt.Printf("%#v", v) } } }
funcSend(key string, value any) { // send to other nodes, net request // if send ok, record to map store.Store(key, value) result := client.send(key, value) if !result { store.Delete(key, value) } }