in datahub/implement.go [164:196]
func (datahub *DataHub) WaitAllShardsReadyWithTime(projectName, topicName string, timeout int64) bool {
ready := make(chan bool)
if timeout > 0 {
go func(timeout int64) {
time.Sleep(time.Duration(timeout) * time.Second)
ready <- false
}(timeout)
}
go func(datahub DataHubApi) {
for {
ls, err := datahub.ListShard(projectName, topicName)
if err != nil {
time.Sleep(1 * time.Microsecond)
continue
}
ok := true
for _, shard := range ls.Shards {
switch shard.State {
case ACTIVE, CLOSED:
continue
default:
ok = false
break
}
}
if ok {
break
}
}
ready <- true
}(datahub)
return <-ready
}