refactor: task system

This commit is contained in:
langhuihui
2024-08-24 22:28:03 +08:00
parent d9f9df06b7
commit c38d3fdc50
11 changed files with 21 additions and 22 deletions

View File

@@ -12,7 +12,8 @@ import (
func createMarcoTask() *MarcoTask {
var mt MarcoTask
mt.initTask(context.Background(), &mt)
mt.Context, mt.CancelCauseFunc = context.WithCancelCause(context.Background())
mt.handler = &mt
mt.Logger = slog.New(slog.NewTextHandler(os.Stdout, nil))
return &mt
}
@@ -67,7 +68,7 @@ func Test_StopByContext(t *testing.T) {
mt := createMarcoTask()
var task Task
ctx, cancel := context.WithCancel(context.Background())
mt.AddTaskWithContext(ctx, &task)
mt.AddTask(&task, ctx)
time.AfterFunc(time.Millisecond*100, cancel)
mt.WaitStopped()
if !task.StopReasonIs(context.Canceled) {