diff options
author | Valery Piashchynski <[email protected]> | 2021-01-25 22:47:02 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-01-25 22:47:02 +0300 |
commit | 43071e43a0743ff8c7913bba7819952962124355 (patch) | |
tree | e3b61113d3c0d28f972c71592af8b2f708994167 /plugins/temporal/workflow/canceller.go | |
parent | 5fd1168c687040ca7d72f4727ee1aec753d3f258 (diff) |
Initial commit of the Temporal plugins set
Diffstat (limited to 'plugins/temporal/workflow/canceller.go')
-rw-r--r-- | plugins/temporal/workflow/canceller.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/plugins/temporal/workflow/canceller.go b/plugins/temporal/workflow/canceller.go new file mode 100644 index 00000000..c38f447f --- /dev/null +++ b/plugins/temporal/workflow/canceller.go @@ -0,0 +1,38 @@ +package workflow + +import ( + "sync" +) + +type ( + cancellable func() error + + canceller struct { + ids sync.Map + } +) + +func (c *canceller) register(id uint64, cancel cancellable) { + c.ids.Store(id, cancel) +} + +func (c *canceller) discard(id uint64) { + c.ids.Delete(id) +} + +func (c *canceller) cancel(ids ...uint64) error { + var err error + for _, id := range ids { + cancel, ok := c.ids.LoadAndDelete(id) + if ok == false { + continue + } + + err = cancel.(cancellable)() + if err != nil { + return err + } + } + + return nil +} |