2020-10-06 10:27:33 +03:00
|
|
|
package asynctask
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
// ContinueFunc is a function that can be connected to previous task with ContinueWith
|
2022-05-31 23:49:21 +03:00
|
|
|
type ContinueFunc[T any, S any] func(context.Context, *T) (*S, error)
|
2020-10-06 10:27:33 +03:00
|
|
|
|
2022-05-31 23:49:21 +03:00
|
|
|
func ContinueWith[T any, S any](ctx context.Context, tsk *Task[T], next ContinueFunc[T, S]) *Task[S] {
|
|
|
|
return Start(ctx, func(fCtx context.Context) (*S, error) {
|
|
|
|
result, err := tsk.Result(fCtx)
|
2020-10-06 10:27:33 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return next(fCtx, result)
|
|
|
|
})
|
|
|
|
}
|