Hi there.
I’m not sure on how to implement this. Currently, with an RPC, I list the matches and send them back with JSON.
Then I implemented a sorting method, everything went well.
Lastly, I want to send out the matches, but only partially. During the first request, I’ll send 10 matches, then if on client side I click on the next button, the server will resume the list function, and then send out the 10 next matches.
Until now I’ve made a goroutine snippet waiting for request input, or timeout to exit the goroutine.
The goroutine
func listMatchGoroutine(ctx context.Context, nk runtime.NakamaModule, logger runtime.Logger, codeInput <-chan int, outMatches chan<- *api.Match) {
limit := 100 //Test only, need to be changed
authoritative := true
minSize := 0
maxSize := 19
label := “”
matches, _ := nk.MatchList(ctx, limit, authoritative, label, minSize, maxSize, "")
idx := 0
outMatches <- matches[idx]
idx = idx + 1
whileFlag := true
for whileFlag {
select {
case receivedCode := <-codeInput:
if receivedCode == 1 {
outMatches <- matches[idx] //SENDING OUT MATCH
idx = idx + 1
} else if receivedCode == 2 {
whileFlag = false
}
case <-time.After(time.Second * 10):
whileFlag = false //TIMEOUT
}
}
}
Calling code
code := make(chan int)
outM := make(chan *api.Match)
go listMatchGoroutine(ctx, nk, logger, code, outM)
receivedMatch := <-outM
logger.Info("0:" + receivedMatch.GetMatchId())
code <- 1
receivedMatch = <-outM
logger.Info("1:" + receivedMatch.GetMatchId())
code <- 1
receivedMatch = <-outM
logger.Info("2:" + receivedMatch.GetMatchId())
code <- 2
The problem now is that I can’t find a way to store the cannels out of the RPC, that I can access with another RPC to continue the listing.
Thanks in advance for the help, I hope I’ve been pretty clear.