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: NEWS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
#### New Features
4
4
5
-
* Aio values `$result`, `$raw` or `$data` now resolve without requiring `call_aio()`. Access the values directly and an NA 'unresolved value' will be returned if the Aio operation is yet to complete.
6
-
* Integer error values generated by all receive functions are now classed 'errorValue' to be immediately distinguishable from possible message values.
5
+
* Aio values `$result`, `$raw` and `$data` now resolve without requiring `call_aio()`. Access the values directly and an NA 'unresolved value' will be returned if the Aio operation is yet to complete.
7
6
*`unresolved()` added as an auxiliary function to query whether an Aio is unresolved, for use in control flow statements.
7
+
* Integer error values generated by receive functions are now classed 'errorValue'. `is_error_value()` helper function included.
8
8
*`is_nul_byte()` added as a helper function for request/reply setups.
9
9
*`survey_time()` added as a convenience function for surveyor/respondent patterns.
10
10
*`logging()` function to specify a global package logging level - 'error' or 'info'. Automatically polls the environment variable 'NANONEXT_LOG' on package load and then each time `logging(level = "check")` is called, allowing this to be set externally.
Copy file name to clipboardExpand all lines: README.Rmd
+38-10Lines changed: 38 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -176,7 +176,7 @@ n$recv(mode = "double")
176
176
177
177
{nanonext} implements true async send and receive, leveraging NNG as a massively-scalable concurrency framework.
178
178
179
-
`send_aio()` and `recv_aio()` functions return immediately but perform their operations async. Their results can be called using `call_aio()` when required.
179
+
`send_aio()` and `recv_aio()` functions return immediately but perform their operations async.
For a 'sendAio' object, calling the result causes it to be stored in the AIO as `$result`. An exit code of 0 denotes a successful send.
188
+
For a 'sendAio' object, the result is stored at `$result`. An exit code of 0 denotes a successful send.
189
+
190
+
- send is successful as long as the message has been accepted by the socket for sending
191
+
- the message may be buffered within the system
192
+
- for acknowledgement of receipt, an RPC setup is required (see next section)
189
193
190
194
```{r async2}
191
195
192
196
res <- send_aio(s1, data.frame(a = 1, b = 2))
193
-
call_aio(res)
194
-
res
195
197
res$result
196
198
197
199
```
198
200
199
-
For a 'recvAio' object, calling the message causes it to be stored in the AIO as `$raw` (if kept) and `$data`.
201
+
For a 'recvAio' object, the message is stored at `$data`, and the raw message at `$raw` (if kept).
200
202
201
203
```{r async3}
202
204
203
205
msg <- recv_aio(s2)
204
-
call_aio(msg)
205
-
msg
206
206
msg$data
207
+
msg$raw
207
208
208
209
```
209
210
210
-
The values can also be accessed directly from the call as per the example below:
211
+
If the async operation is yet to complete, a logical NA 'unresolved value' will be returned. In the below example an async receive is requested, but no mesages are waiting (yet to be sent).
211
212
212
213
```{r async4}
213
214
215
+
msg <- recv_aio(s2)
216
+
msg$data
217
+
218
+
```
219
+
220
+
For use in control flow statements, `unresolved` can be used. Note that calling this function queries for resolution itself and may cause a previously unresolved Aio to resolve.
221
+
222
+
```{r async5}
223
+
224
+
# unresolved() already queries for resolution so no need for it again within the while clause
225
+
226
+
while (unresolved(msg)) {
227
+
# do stuff here before checking resolution again
228
+
send_aio(s1, "resolved")
229
+
}
230
+
231
+
msg$data
232
+
```
233
+
234
+
The values may also be called explicitly using `call_aio()`. This will wait for completion of the Aio (blocking).
235
+
236
+
```{r async6}
237
+
238
+
# will wait for completion then return the resolved Aio
239
+
call_aio(msg)
240
+
241
+
# to access the resolved value directly (waiting if required)
214
242
call_aio(msg)$data
215
243
216
244
close(s1)
217
245
close(s2)
218
246
219
247
```
220
248
221
-
As an example of possible applications, the {mirai} package <https://shikokuchuo.net/mirai/> (available on CRAN) uses {nanonext} as the back-end to provide asynchronous execution of arbitrary R code.
222
-
223
249
[« Back to ToC](#table-of-contents)
224
250
225
251
### RPC and Distributed Computing
@@ -272,6 +298,8 @@ In this example the calculation is returned, but other operations may reside ent
272
298
273
299
In such a case, using `call_aio()` confirms that the operation has completed (or it will wait for completion) and calls the return value of the function, which may typically be NULL or an exit code.
274
300
301
+
The {mirai} package <https://shikokuchuo.net/mirai/> (available on CRAN) uses {nanonext} as the back-end to provide asynchronous execution of arbitrary R code using the RPC model.
0 commit comments