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
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, implementing a cross-platform standard for messaging and communications. Leveraging asynchronous execution, serves as a concurrency framework for building distributed applications.
24
+
R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is a socket library providing high-performance scalability protocols, implementing a cross-platform standard for messaging and communications. Serves as a concurrency framework for building distributed applications, utilising 'Aio' objects which return an unresolved value whilst its asynchronous operation is ongoing, automatically resolving to a final value once complete.
25
25
26
26
Designed for performance and reliability, the NNG library is written in C and {nanonext} is a lightweight wrapper depending on no other packages. Provides the interface for code and processes to communicate with each other - receive data generated in Python, perform analysis in R, and send results to a C++ program – all on the same computer or on networks spanning the globe.
27
27
@@ -176,15 +176,26 @@ n$recv(mode = "double")
176
176
177
177
{nanonext} implements true async send and receive, leveraging NNG as a massively-scaleable concurrency framework.
178
178
179
-
`send_aio()` and `recv_aio()` functions return immediately but perform their operations async.
180
-
181
179
```{r async}
182
180
library(nanonext)
183
181
s1 <- socket("pair", listen = "inproc://nano")
184
182
s2 <- socket("pair", dial = "inproc://nano")
185
183
186
184
```
187
185
186
+
`send_aio()` and `recv_aio()` functions return immediately with an 'Aio' object, but perform their operations async.
187
+
188
+
An 'Aio' object returns an unresolved value whilst its asynchronous operation is ongoing, automatically resolving to a final value once complete.
189
+
190
+
```{r async4}
191
+
192
+
# an async receive is requested, but no mesages are waiting (yet to be sent)
193
+
msg <- recv_aio(s2)
194
+
msg
195
+
msg$data
196
+
197
+
```
198
+
188
199
For a 'sendAio' object, the result is stored at `$result`.
189
200
190
201
```{r async2}
@@ -203,36 +214,26 @@ For a 'recvAio' object, the message is stored at `$data`, and the raw message at
203
214
204
215
```{r async3}
205
216
206
-
msg <- recv_aio(s2)
207
-
msg
217
+
# now that a message has been sent, the 'recvAio' automatically resolves
208
218
msg$data
209
219
msg$raw
210
220
211
221
```
212
222
213
-
If the async operation is yet to complete, an 'unresolved' logical NA value will be returned.
214
-
215
-
```{r async4}
223
+
Auxiliary function `unresolved()` may be used in control flow statements to perform actions which depend on resolution of the Aio, both before and after. This means there is no need to actually wait (block) for an Aio to resolve, as the example below demonstrates.
216
224
217
-
# an async receive is requested, but no mesages are waiting (yet to be sent)
225
+
```{r async5}
218
226
219
227
msg <- recv_aio(s2)
220
-
msg$data
221
-
222
-
```
223
-
224
-
Auxiliary function `unresolved()` can be used in control flow statements.
225
-
226
-
```{r async5}
227
228
228
229
# unresolved() queries for resolution itself so no need to use it again within the while clause
229
-
230
230
while (unresolved(msg)) {
231
231
# do stuff before checking resolution again
232
232
send_aio(s1, "resolved")
233
233
cat("unresolved")
234
234
}
235
235
236
+
# perform actions which depend on the Aio value outside the while loop
0 commit comments