1 Star 2 Fork 0

TimAndy/routine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api_future.go 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
TimAndy 提交于 2022-07-20 21:10 +08:00 . Rename type Any to any
package routine
import "time"
// CancelToken propagates notification that operations should be canceled.
type CancelToken interface {
// IsCanceled returns true if task was canceled.
IsCanceled() bool
// Cancel notifies the waiting coroutine that the task has canceled and returns stack information.
Cancel()
}
// Future provide a way to wait for the sub-coroutine to finish executing, get the return value of the sub-coroutine, and catch the sub-coroutine panic.
type Future interface {
// IsDone returns true if completed in any fashion: normally, exceptionally or via cancellation.
IsDone() bool
// IsCanceled returns true if task was canceled.
IsCanceled() bool
// IsFailed returns true if completed exceptionally.
IsFailed() bool
// Complete notifies the waiting coroutine that the task has completed normally and returns the execution result.
Complete(result any)
// Cancel notifies the waiting coroutine that the task has canceled and returns stack information.
Cancel()
// Fail notifies the waiting coroutine that the task has terminated due to panic and returns stack information.
Fail(error any)
// Get return the execution result of the sub-coroutine, if there is no result, return nil.
// If task is canceled, a panic with cancellation will be raised.
// If panic is raised during the execution of the sub-coroutine, it will be raised again at this time.
Get() any
// GetWithTimeout return the execution result of the sub-coroutine, if there is no result, return nil.
// If task is canceled, a panic with cancellation will be raised.
// If panic is raised during the execution of the sub-coroutine, it will be raised again at this time.
// If the deadline is reached, a panic with timeout error will be raised.
GetWithTimeout(timeout time.Duration) any
}
// NewFuture Create a new instance.
func NewFuture() Future {
fut := &future{}
fut.await.Add(1)
return fut
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/timandy/routine.git
git@gitee.com:timandy/routine.git
timandy
routine
routine
main

搜索帮助