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 which is determined some time in future.
func Create ¶ added in v0.1.0
Create creates a future fut, which can be resolved by determine.
Created future might have both the value and the error with non-empty value.
func New ¶
New creates a future fut, which can be resolved by res or rejected by rej.
Created future will only have at most one non-empty value. If it is resolved by res, fut.Err() will be nil; fut.Get() returns empty value if 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.