summaryrefslogtreecommitdiff
path: root/plugins/temporal/workflow/canceller.go
blob: c38f447fde734ce50f942d1bf93052ab4f21a32b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}