blob: e1a1aa9f7a71a3a81ad8a56782b12b46f5226f9a [file] [log] [blame]
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package task implements tasks involved in making a Go release.
package task
import (
// CommunicationTasks combines communication tasks together.
type CommunicationTasks struct {
var AwaitDivisor int = 1
// AwaitCondition calls the condition function every period until it returns
// true to indicate success, or an error. If the condition succeeds,
// AwaitCondition returns its result.
func AwaitCondition[T any](ctx *workflow.TaskContext, period time.Duration, condition func() (T, bool, error)) (T, error) {
pollTimer := time.NewTicker(period / time.Duration(AwaitDivisor))
defer pollTimer.Stop()
for {
select {
case <-ctx.Done():
var zero T
return zero, ctx.Err()
case <-pollTimer.C:
res, done, err := condition()
if done || err != nil {
return res, err