You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: USAGE.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -134,9 +134,35 @@ the actor is not blocked.
134
134
to `GetEmployee` for different employee ids or _the same_ employee id.
135
135
In the latter case a second call to the database will occur.
136
136
The code could be engineered to prevent this if desired but let's assume we don't mind the odd extra call to the database.
137
+
* If we did want to prevent this one way would be to pause the actor whilst we wait for the database to return. In this particular case that would probably be a little heavy-handed but a means of doing this is described below.
137
138
1. Finally, if the call to the database causes an exception because, say, no employee exists for the given `payrollId` then that exception
138
139
will be passed up to the code that called into the `EmployeeCache` object.
139
140
141
+
### Pausing the actor during an `await`
142
+
143
+
Let's say you wanted to ensure only one call to the database to get an employee.
144
+
A rather blunt way of doing that would be to essentially pause the actor until the database call returns.
145
+
You'd achieve that using the `WhileActorPaused` extension:
Essentially this will prevent the actor from doing anything at all until the task returned by `_database.GetEmployee(payrollId)` completes and the first thing processed by the actor when it resumes will be the continuation after the call (i.e. `_cache[payrollId] = ...`).
164
+
This device should be used with caution - and would most likely be inappropriate in the case of this example - but could be useful in some circumstances.
165
+
140
166
## Specifying work to do when the actor starts
141
167
142
168
Sometimes it's useful to to specify work that the actor must do when it starts prior to processing any more work.
0 commit comments