-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime_callee.go
71 lines (59 loc) · 1.92 KB
/
runtime_callee.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package core
import (
"fmt"
"git.golaxy.org/core/internal/concurrent"
"git.golaxy.org/core/runtime"
"git.golaxy.org/core/util/generic"
)
var (
ErrProcessQueueClosed = fmt.Errorf("%w: process queue is closed", ErrRuntime) // 任务处理流水线关闭
ErrProcessQueueFull = fmt.Errorf("%w: process queue is full", ErrRuntime) // 任务处理流水线已满
)
// PushCall 将调用函数压入接受者的任务处理流水线,返回AsyncRet。
func (rt *RuntimeBehavior) PushCall(fun generic.FuncVar0[any, runtime.Ret], va ...any) runtime.AsyncRet {
return rt.pushCallTask(_Task{
fun: fun,
va: va,
})
}
// PushCallDelegate 将调用委托压入接受者的任务处理流水线,返回AsyncRet。
func (rt *RuntimeBehavior) PushCallDelegate(fun generic.DelegateFuncVar0[any, runtime.Ret], va ...any) runtime.AsyncRet {
return rt.pushCallTask(_Task{
delegateFun: fun,
va: va,
})
}
// PushCallVoid 将调用函数压入接受者的任务处理流水线,返回AsyncRet。
func (rt *RuntimeBehavior) PushCallVoid(fun generic.ActionVar0[any], va ...any) runtime.AsyncRet {
return rt.pushCallTask(_Task{
action: fun,
va: va,
})
}
// PushCallVoidDelegate 将调用委托压入接受者的任务处理流水线,返回AsyncRet。
func (rt *RuntimeBehavior) PushCallVoidDelegate(fun generic.DelegateActionVar0[any], va ...any) runtime.AsyncRet {
return rt.pushCallTask(_Task{
delegateAction: fun,
va: va,
})
}
func (rt *RuntimeBehavior) pushCallTask(task _Task) (asyncRet chan runtime.Ret) {
task.typ = _TaskType_Call
task.asyncRet = concurrent.MakeAsyncRet()
asyncRet = task.asyncRet
defer func() {
if panicInfo := recover(); panicInfo != nil {
asyncRet <- runtime.MakeRet(nil, ErrProcessQueueClosed)
close(asyncRet)
}
}()
select {
case rt.processQueue <- task:
return
default:
break
}
asyncRet <- runtime.MakeRet(nil, ErrProcessQueueFull)
close(asyncRet)
return
}