dingdayu-go-asyncGo 安全异步任务
Go 安全异步任务
基于 Go 的安全异步包。
安装
go get github.com/dingdayu/async/v2
示例
package main
import (
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/dingdayu/async/v2"
)
type ExampleAsync struct {
}
// OnPreRun: 运行之前的调用, panic 会导致注册失败
func (a ExampleAsync) OnPreRun() {
fmt.Printf("\u001B[1;30;42m[info]\u001B[0m ExampleAsync 注册成功,开始运行!\n")
}
// Name: 异步任务的名称,需要在进程内唯一,否则会被替换
func (a ExampleAsync) Name() string {
return "example"
}
// Handle: 异步任务的核心逻辑,通过 for 进行巡航,通过 context 进行安全退出
func (a ExampleAsync) Handle(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
for {
select {
default:
// todo:: Logical unit
time.Sleep(3 * time.Second)
fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
case <-ctx.Done():
return
}
}
}
// OnShutdown: 在退出前并行调用
func (a ExampleAsync) OnShutdown(s os.Signal) {
fmt.Printf("\u001B[1;30;42m[info]\u001B[0m ExampleAsync 接收到系统信号[%s],准备退出!\n", s.String())
}
func main() {
// 处理系统 SIGINT and SIGTERM 信号.
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
ayc := async.NewAsync(context.Background(), ch)
_ = ayc.Register(ExampleAsync{})
ayc.Wait()
fmt.Println("[1;30;42m[info]\u001B[0m Task exited")
}
评论
LiteJob异步任务处理器
基于Golang与Redis开发的高速、安全的异步任务处理器。支持多种存储协议: 1.Redis 2.Sqlite 3.Mysql 4.InMemory
LiteJob异步任务处理器
0
TaskQueue-swiftiOS 异步任务队列
TaskQueue(swift) 是个非常强大的 Swift 类,用来管理异步任务,需要一个一个的执
TaskQueue-swiftiOS 异步任务队列
0
Celery异步任务队列
Celery是一个简单,灵活且可靠的分布式系统,可以处理大量消息,同时为操作提供维护该系统所需的工具。这是一个任务队列,着重于实时处理,同时还支持任务调度。Celery通过消息进行通信,通常使用经纪人
Celery异步任务队列
0
TaskQueue-swiftiOS 异步任务队列
TaskQueue(swift)是个非常强大的Swift类,用来管理异步任务,需要一个一个的执行,用户只负责添加任务到队列,队列会排序然后一个一个执行。
TaskQueue-swiftiOS 异步任务队列
0