Documentation
¶
Overview ¶
Package async implements a simple Promise API.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Promise ¶
type Promise chan struct{}
Promise is a simple notification primitive for asynchronous events.
func (Promise) Resolve ¶
func (s Promise) Resolve()
Resolve wakes any clients currently waiting on the Promise
func (Promise) Wait ¶
func (s Promise) Wait()
Wait synchronously blocks until the Promise is resolved.
Example ¶
Output: Pre-wait logic runs. Async routine completes. Post-wait logic runs.
func (Promise) WaitWithPeriodicTask ¶
WaitWithPeriodicTask repeatedly invokes |task| with period |period| until the Promise is resolved.
Example ¶
Unfortunately, this example is not made testable because it inherently operates as a race condition between two independent things. To get a deterministic test, the `resolve` would need to be triggered by the periodic task, making for an extremely contrived example. This example errs on the side of providing a more standard use case.
Output: