util: Add safe easy ack that allows multiple ack's

Just another sync utility to make code more readable.
This commit is contained in:
James Shubin
2019-03-24 20:57:19 -04:00
parent 398706246e
commit 7d96623f06
2 changed files with 51 additions and 0 deletions

View File

@@ -64,6 +64,28 @@ func TestEasyAck3(t *testing.T) {
}
}
func TestEasyAckOnce1(t *testing.T) {
eao := NewEasyAckOnce()
eao.Ack()
eao.Ack() // must not panic
eao.Ack()
select {
case <-eao.Wait(): // we got it!
case <-time.After(time.Duration(60) * time.Second):
t.Errorf("the Ack did not arrive in time")
}
}
func TestEasyAckOnce2(t *testing.T) {
eao := NewEasyAckOnce()
// never send an ack
select {
case <-eao.Wait(): // we got it!
t.Errorf("the Ack arrived unexpectedly")
default:
}
}
func ExampleSubscribeSync() {
fmt.Println("hello")