asyncutil

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParallelFor added in v0.7.4

func ParallelFor(start, end int, task func(int) any, numGoroutines ...int) []any

ParallelFor 用於平行處理指定範圍內的數值

func ParallelForEach added in v0.7.4

func ParallelForEach(data any, task any, numGoroutines ...int) []any

ParallelForEach 用於平行處理 for range 迴圈,支援切片和 map

Types

type Awaitable

type Awaitable struct {
	// contains filtered or unexported fields
}

Awaitable 表示一個可以等待的結果

func Async

func Async(fn any, args ...any) *Awaitable

Async 創建一個異步操作,並返回 Awaitable

func NewAwaitable

func NewAwaitable(fn any, args ...any) *Awaitable

NewAwaitable 創建一個新的 Awaitable

func (*Awaitable) Await

func (a *Awaitable) Await() ([]any, error)

Await 等待結果,返回結果切片和 error

type Task added in v0.7.2

type Task struct {
	ID   string // 任務的標識符
	Fn   any    // 要執行的函數
	Args []any  // 函數的參數切片
}

Task 結構體,包含要執行的函數、其對應的參數和標識符

type TaskResult added in v0.7.2

type TaskResult struct {
	ID      string // 任務的標識符
	Results []any  // 函數返回的結果
}

TaskResult 結構體,包含每個任務的結果和標識符

func ParallelProcess added in v0.7.1

func ParallelProcess(tasks []Task) []TaskResult

ParallelProcess 接受一個 Task 切片,平行執行所有的函數並返回結果。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL