-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathfuture.go
More file actions
34 lines (25 loc) · 1.07 KB
/
future.go
File metadata and controls
34 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package pond
// Task represents a task that can be waited on. If the task fails, the error can be retrieved.
type Task interface {
// Done returns a channel that is closed when the task is complete or has failed.
Done() <-chan struct{}
// Wait waits for the task to complete and returns any error that occurred.
Wait() error
}
// ResultTask represents a task that yields a result. If the task fails, the error can be retrieved.
type ResultTask[R any] interface {
// Done returns a channel that is closed when the task is complete or has failed.
Done() <-chan struct{}
// Wait waits for the task to complete and returns the result and any error that occurred.
Wait() (R, error)
}
// Result is deprecated. Use ResultTask instead.
// This interface is maintained for backward compatibility.
//
// Deprecated: Use ResultTask instead.
type Result[R any] interface {
// Done returns a channel that is closed when the task is complete or has failed.
Done() <-chan struct{}
// Wait waits for the task to complete and returns the result and any error that occurred.
Wait() (R, error)
}