Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maybe][DesignPattern]New command to waitUntil a channel becomes empty #405

Open
longquanzheng opened this issue Jul 22, 2024 · 0 comments

Comments

@longquanzheng
Copy link
Contributor

longquanzheng commented Jul 22, 2024

Use case: need to wait for channel A has msg but channel B is empty. It’s very hard to workaround atm.

More details / context: a main thread starts a side thread. The side thread runs as a loop to wait for an action channel for a msg. When receives a message, make an action then go back to wait for next one.

Main thread then send the msg anytime. When the main thread exists, we want to drain the msg for the side thread and then complete the workflow.

Main thread cannot use force complete because side thread could still be running or there are more msg in the channel. We can’t use graceful complete on both because side thread will always running as a loop.

Current workaround is to let main thread graceful complete also set a DA and send a msg to a special channel to tell side thread to attempt to complete when the channel is empty. Then side thread would wait on the msg. On receiving the msg, stop waiting for the action channel , then use the DA to switch to use conditional complete to go to the loop.

Better workaround 2: , instead of a new channel and data attribute , send a NULL to the action channel instead. When receiving the NULL, then graceful complete —- because of the FIFO nature of a single channel —- this can be extended to wait for multiple NULLs for more complex cases (use a counter to track how many NULLs have been received)

Workaround 3: just use persistence locking to make multi threading running in series

@longquanzheng longquanzheng changed the title New command to wait for check a channel is empty New command to waitUntil a channel becomes empty Sep 11, 2024
@longquanzheng longquanzheng changed the title New command to waitUntil a channel becomes empty [need use case]New command to waitUntil a channel becomes empty Sep 11, 2024
@longquanzheng longquanzheng changed the title [need use case]New command to waitUntil a channel becomes empty New command to waitUntil a channel becomes empty Sep 13, 2024
@longquanzheng longquanzheng changed the title New command to waitUntil a channel becomes empty [Maybe][DesignPattern]New command to waitUntil a channel becomes empty Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant