go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/async/actioner.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package async 9 10 import "context" 11 12 // Actioner is a type that can be used as a tracked action. 13 type Actioner[T, V any] interface { 14 Action(context.Context, T) (V, error) 15 } 16 17 // ActionerFunc is a function that implements action. 18 type ActionerFunc[T, V any] func(context.Context, T) (V, error) 19 20 // Action implements actioner for the function. 21 func (af ActionerFunc[T, V]) Action(ctx context.Context, args T) (V, error) { 22 return af(ctx, args) 23 } 24 25 // NoopActioner is an actioner type that does nothing. 26 type NoopActioner[T, V any] struct{} 27 28 // Action implements actioner 29 func (n NoopActioner[T, V]) Action(_ context.Context, _ T) (out V, err error) { 30 return 31 }