-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IWF-369: Remove key from map when signal/internal channel is empty (#495
- Loading branch information
1 parent
1d24724
commit 1352220
Showing
7 changed files
with
79 additions
and
83 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package interpreter | ||
|
||
import "github.com/indeedeng/iwf/gen/iwfidl" | ||
|
||
type InternalChannel struct { | ||
// key is channel name | ||
receivedData map[string][]*iwfidl.EncodedObject | ||
} | ||
|
||
func NewInternalChannel() *InternalChannel { | ||
return &InternalChannel{ | ||
receivedData: map[string][]*iwfidl.EncodedObject{}, | ||
} | ||
} | ||
|
||
func RebuildInternalChannel(refill map[string][]*iwfidl.EncodedObject) *InternalChannel { | ||
return &InternalChannel{ | ||
receivedData: refill, | ||
} | ||
} | ||
|
||
func (i *InternalChannel) GetAllReceived() map[string][]*iwfidl.EncodedObject { | ||
return i.receivedData | ||
} | ||
|
||
func (i *InternalChannel) HasData(channelName string) bool { | ||
l := i.receivedData[channelName] | ||
return len(l) > 0 | ||
} | ||
|
||
func (i *InternalChannel) ProcessPublishing(publishes []iwfidl.InterStateChannelPublishing) { | ||
for _, pub := range publishes { | ||
i.receive(pub.ChannelName, pub.Value) | ||
} | ||
} | ||
|
||
func (i *InternalChannel) receive(channelName string, data *iwfidl.EncodedObject) { | ||
l := i.receivedData[channelName] | ||
l = append(l, data) | ||
i.receivedData[channelName] = l | ||
} | ||
|
||
func (i *InternalChannel) Retrieve(channelName string) *iwfidl.EncodedObject { | ||
l := i.receivedData[channelName] | ||
if len(l) <= 0 { | ||
panic("critical bug, this shouldn't happen") | ||
} | ||
data := l[0] | ||
l = l[1:] | ||
if len(l) == 0 { | ||
delete(i.receivedData, channelName) | ||
} else { | ||
i.receivedData[channelName] = l | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters