updatabletimer

package
v0.0.0-...-94a9b73 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

Updatable Timer Sample

A helper structure that supports blocking sleep that can be rescheduled at any moment.

Demonstrates:

  • Timer and its cancellation
  • Signal Channel
  • Selector used to wait on both timer and channel
Steps to run this sample:
  1. You need a Temporal service running. See details in README.md
  2. Run the following command to start the worker
go run updatabletimer/worker/main.go
  1. Run the following command to start the example
go run updatabletimer/starter/main.go
  1. Run the following command to update the timer wake-up time
go run updatabletimer/updater/main.go

Documentation

Index

Constants

View Source
const (
	TaskQueue  = "updatable-timer"
	WorkflowID = "updatable-timer"
	QueryType  = "GetWakeUpTime"
	SignalType = "UpdateWakeUpTime"
)

Variables

This section is empty.

Functions

func Workflow

func Workflow(ctx workflow.Context, initialWakeUpTime time.Time) error

Workflow that sleeps initialWakeUpTime unless the new wake-up time is received through "UpdateWakeUpTime" signal.

Types

type UpdatableTimer

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

UpdatableTimer is an example of a timer that can have its wake time updated

func (*UpdatableTimer) GetWakeUpTime

func (u *UpdatableTimer) GetWakeUpTime() time.Time

func (*UpdatableTimer) SleepUntil

func (u *UpdatableTimer) SleepUntil(ctx workflow.Context, wakeUpTime time.Time, updateWakeUpTimeCh workflow.ReceiveChannel) (err error)

SleepUntil sleeps until the provided wake-up time. The wake-up time can be updated at any time by sending a new time over updateWakeUpTimeCh. Supports ctx cancellation. Returns temporal.CanceledError if ctx was canceled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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