Itask
Golang task manager, including call chain, sync, async and parallel executor.
Install / Use
/learn @linxabc/ItaskREADME
itask
Go task manager, including call chain, sync, async and parallel executor.
Usage:
basic chain call:
If any MapIf func return false, the following call will not execute.
func TestChain(t *testing.T) {
NewChain().Call(test1, 1).MapIf(func(x int) bool { return x > 0 }, -1).Call(test1, 2)
}
func test1(a int) {
fmt.Println(a)
}
bool chain call:
Every funcs must return bool value, and if previous func return false, the following funcs will not execute.
func TestBoolChainCall(t *testing.T) {
NewBoolChain().Call(less, 1, 2).Call(less, 5, 2).Call(2, 3)
}
func TestBoolChain(t *testing.T) {
c := NewBoolChain()
c.Append(less, 1, 2)
c.Append(less, 5, 2)
c.Prepend(less, 2, 3)
fmt.Println(c.Run())
}
func less(a, b int) bool {
fmt.Printf("compare %d, %d\n", a, b)
return a < b
}
task schedule:
Register funcs, control process in pipeline, parallel, or async execute.
func TestTask(t *testing.T) {
task := NewTask()
task.PreProcess(test2, 1)
task.Process(test2, 2)
task.Process(testPanic)
task.PostProcess(test2, 3)
task.SetRecover(testRecover)
task.Run() // sync, execute one by one
task.Parallel() // run parallel, wait for all go routine finish
task.Async() // async, return immediately without waiting for response
time.Sleep(100 * time.Millisecond)
}
func test2(a int) {
fmt.Println(a)
}
func testPanic() {
panic("aaa")
}
func testRecover(r *RecoverMsg) {
fmt.Println("recover: ", r.FuncName, r.StartTime, r.Err)
}
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
