Skip to content

Instantly share code, notes, and snippets.

@steevehook
Last active May 21, 2019 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steevehook/03814f766176a4839ade2531e121dbb0 to your computer and use it in GitHub Desktop.
Save steevehook/03814f766176a4839ade2531e121dbb0 to your computer and use it in GitHub Desktop.
func waitTillTableHasCount(conn sqlbuilder.Database, table string, n int) error {
timeout := time.After(5 * time.Second)
for {
select {
case <-timeout:
count, err := conn.Collection(table).Find().Count()
if err != nil {
return err
}
return fmt.Errorf(
"timeout occurred while waiting for table: %s to have expected: %d rows, but got: %d rows",
table,
n,
int(count),
)
case <-time.After(10 * time.Millisecond):
count, err := conn.Collection(table).Find().Count()
if err == nil && int(count) == n {
return nil
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment