Stream legal landings with pull
Bob selects his new king on 2. The worker runs king-jumps and streams each possible first landing. Bob receives square 11 and the square of the red king he would capture, 7. He then reads the finish and completion notices.
Go example
func pull(t *testing.T, ctx context.Context, db *stardust.Database) {
worker := must(stardust.Accept[int64](db, "pull", "checkers/legal"))
defer worker.Close()
board(db)
call := must(stardust.OpenExchange[candidate](ctx, db, "pull", "checkers/legal", int64(2)))
defer call.Close()
open := must(worker.Next(ctx))
for _, row := range must(stardust.CallAs[[]candidate](db, table, "king-jumps", open.Data)) {
check(worker.Send(open.Handle, row))
}
check(worker.Finish(open.Handle))
item := must(call.Next(ctx))
if item.Kind != "message" || item.Data != (candidate{11, 7}) {
t.Fatal(item)
}
if must(call.Next(ctx)).Kind != "finish" || must(call.Next(ctx)).Kind != "complete" {
t.Fatal("incomplete pull")
}
}