Documentation
¶
Overview ¶
Package future defines Future, a value which is determined some time in future.
Future is designed for writing long-running program which doing some works repeatedly like crawlers. It's good to be used as a broadcaster, or as a param to task generator.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() crawlerTask, pageFuture := downloadWebPage() log.Print(task.Skip( task.Iter( crawlerTask, parseAndSavePage(pageFuture), task.Skip( notifyWebDash(pageFuture), cleanUpOldData(pageFuture), ), ).Timed(time.Minute).RetryN(3).Loop(), task.HTTPServer(myWebDash), ).Run(ctx))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Future ¶
type Future[T any] struct { // contains filtered or unexported fields }
Future represents a value will be resolved or rejected some time in future. The term "resolve" indicates the value is computed successfully.
Future implements [task.Task] so it's easier to wait for multiple futures.
err = task.Skip(future1, future2, future3).Run(ctx)
if err != nil {
// one or more futures are rejected
}
func (*Future[T]) Await ¶
Await is a helper which waits the value and retrieves it along with the error.
func (*Future[T]) Done ¶
func (f *Future[T]) Done() <-chan struct{}
Done returns a channel which is closed when value is determined.
Click to show internal directories.
Click to hide internal directories.