summaryrefslogtreecommitdiff
path: root/plugins/temporal/workflow/id_registry.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-25 22:47:02 +0300
committerValery Piashchynski <[email protected]>2021-01-25 22:47:02 +0300
commit43071e43a0743ff8c7913bba7819952962124355 (patch)
treee3b61113d3c0d28f972c71592af8b2f708994167 /plugins/temporal/workflow/id_registry.go
parent5fd1168c687040ca7d72f4727ee1aec753d3f258 (diff)
Initial commit of the Temporal plugins set
Diffstat (limited to 'plugins/temporal/workflow/id_registry.go')
-rw-r--r--plugins/temporal/workflow/id_registry.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/temporal/workflow/id_registry.go b/plugins/temporal/workflow/id_registry.go
new file mode 100644
index 00000000..ac75cbda
--- /dev/null
+++ b/plugins/temporal/workflow/id_registry.go
@@ -0,0 +1,51 @@
+package workflow
+
+import (
+ "sync"
+
+ bindings "go.temporal.io/sdk/internalbindings"
+)
+
+// used to gain access to child workflow ids after they become available via callback result.
+type idRegistry struct {
+ mu sync.Mutex
+ ids map[uint64]entry
+ listeners map[uint64]listener
+}
+
+type listener func(w bindings.WorkflowExecution, err error)
+
+type entry struct {
+ w bindings.WorkflowExecution
+ err error
+}
+
+func newIDRegistry() *idRegistry {
+ return &idRegistry{
+ ids: map[uint64]entry{},
+ listeners: map[uint64]listener{},
+ }
+}
+
+func (c *idRegistry) listen(id uint64, cl listener) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ c.listeners[id] = cl
+
+ if e, ok := c.ids[id]; ok {
+ cl(e.w, e.err)
+ }
+}
+
+func (c *idRegistry) push(id uint64, w bindings.WorkflowExecution, err error) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ e := entry{w: w, err: err}
+ c.ids[id] = e
+
+ if l, ok := c.listeners[id]; ok {
+ l(e.w, e.err)
+ }
+}