Last active
January 18, 2016 07:12
-
-
Save minustore/5da4e9414f95b6d99a4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "time" | |
import "sync" | |
func confirm(done chan bool) { | |
for { | |
select{ | |
case <-done: | |
fmt.Println("confirm") | |
} | |
} | |
} | |
func clientConfirm(id string) { | |
TradeConfirmList.mux.Lock() | |
if done, ok := TradeConfirmList.channelList[id]; ok { | |
fmt.Println("get client confirm") | |
done <- true | |
delete (TradeConfirmList.channelList, id) | |
} else { | |
fmt.Println("id Not Found") | |
} | |
TradeConfirmList.mux.Unlock() | |
} | |
func makeTrade() { | |
done := make(chan bool, 1) | |
TradeConfirmList.mux.Lock() | |
defer TradeConfirmList.mux.Unlock() | |
TradeConfirmList.channelList["test"] = done | |
fmt.Println("get trade") | |
go confirm(done) | |
fmt.Println("wait for confirm trade") | |
} | |
type TradeConfirm struct { | |
channelList map[string]chan bool | |
mux sync.Mutex | |
} | |
var TradeConfirmList TradeConfirm | |
func main() { | |
TradeConfirmList = TradeConfirm{channelList: make(map[string]chan bool)} | |
go makeTrade() | |
time.Sleep(time.Second*3) | |
go clientConfirm("test") | |
for{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment