helpers

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package helpers contains helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommaDelimitedOptionalValue

func CommaDelimitedOptionalValue(vals []string) *string

CommaDelimitedOptionalValue takes an array of strings and returns a pointer to a string containing all values concatenated with commas, or nil if the array is empty.

Types

type HTTPResponse

type HTTPResponse interface {
	StatusCode() int
	Status() string
}

type TaskPoller

type TaskPoller[T HTTPResponse] struct {
	// contains filtered or unexported fields
}

TaskPoller is a helper to poll an API for the status of an asynchronous task. It will call the provided taskFunc to get the latest task status and will continue polling until the task completes (succeeds or fails) or an error occurs.

func NewTaskPoller

func NewTaskPoller[T HTTPResponse](taskID string, taskFunc func() (T, error)) *TaskPoller[T]

NewTaskPoller creates a new TaskPoller. taskID is the ID of the asynchronous task to poll. taskFunc is a function that will be called to get the latest status of the task. It should return a HTTPResponse and an error.

func (*TaskPoller[T]) Err

func (s *TaskPoller[T]) Err() error

Err returns the first error encountered while polling.

func (*TaskPoller[T]) Poll

func (s *TaskPoller[T]) Poll(ctx context.Context) bool

Poll calls taskFunc to get the latest task status. It will continue polling until the task completes (succeeds or fails) or an error occurs. Returns true if polling should continue, false otherwise.

func (*TaskPoller[T]) Resp

func (s *TaskPoller[T]) Resp() T

Resp returns the latest response from calling taskFunc.

Jump to

Keyboard shortcuts

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