How to observe/wait for a Grain state #7439
-
hi everyone, I've the following scenario:
I want to wait for a specific state in the grain. Without orleans i would implement it with a task completion source. And return the corresponding Task in WaitForMax(). But what is the correct technqiue to implement it with orelans as a backend? Of course my real scenario is not a int value. In the grain i get messages via a orleans stream. The grain is doing some processing on this messages and should signal a completed processing somehow to other grains. But in a simplified view it's similart to the integer example. Thanks :). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi Toni, One way to accomplish this is via a callback: your waiter grain can call the observee grain with Within the observee grain, you can use a TaskCompletionSource if you wish. I would advise creating the TCS with How do those suggestions sound to you, will one of them be appropriate? |
Beta Was this translation helpful? Give feedback.
Hi Toni,
One way to accomplish this is via a callback: your waiter grain can call the observee grain with
await targetGrain.CallMeWhenX(IWaiterGrain)
and your observee grain can issue a callback when it's time.Another option is to poll / long poll:
Task<Status> PollForX()
which can return after 5 seconds with a timeout status if the condition is not met (mark it as[AlwaysInterleave]
so that other methods can execute while it's running).A third option is a hybrid of those two: registering a callback periodically. The benefit of that approach is that it doesn't require any persistence in the observee.
Another option is to use streams: the observee can push a notification that the conditi…