Skip to content

Commit 967bfc6

Browse files
committed
unresolved() rather than is_resolved()
1 parent 1659d50 commit 967bfc6

File tree

11 files changed

+70
-62
lines changed

11 files changed

+70
-62
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.2.0.9003
4+
Version: 0.2.0.9004
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library providing high-performance scalability protocols,
77
implementing a cross-platform standard for messaging and communications.

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export(call_aio)
2727
export(context)
2828
export(dial)
2929
export(is_nul_byte)
30-
export(is_resolved)
3130
export(listen)
3231
export(logging)
3332
export(nano)
@@ -47,6 +46,7 @@ export(socket)
4746
export(stop_aio)
4847
export(subscribe)
4948
export(survey_time)
49+
export(unresolved)
5050
export(unsubscribe)
5151
importFrom(stats,start)
5252
importFrom(utils,.DollarNames)

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# nanonext 0.2.0.9003 (development)
1+
# nanonext 0.2.0.9004 (development)
22

33
#### New Features
44

55
* Aio fields `$result` for a 'sendAio', `$raw` and `$data` for a 'recvAio' may be queried directly, returning their values or else an NA 'unresolved value' if the Aio operation is yet to complete.
6-
* `is_resolved()` added as an auxiliary function to query whether an Aio has resolved in a non-blocking fashion.
6+
* `unresolved()` added as an auxiliary function to query whether an Aio is still unresolved in a non-blocking fashion.
77
* `is_nul_byte()` added as a helper function for request/reply setups.
88
* `survey_time()` added as a convenience function for surveyor/respondent patterns.
99
* `logging()` function to specify a global package logging level - currently supports 'error' and 'info'.

R/aio.R

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#' @section Non-blocking:
3030
#'
3131
#' To query the value of an Aio without potentially waiting for the Aio
32-
#' operation to complete, call the values directly at \code{$result} for a 'sendAio', and
33-
#' \code{$raw} or \code{$data} for a 'recvAio'.
32+
#' operation to complete, access the values directly at \code{$result} for a
33+
#' 'sendAio', and \code{$raw} or \code{$data} for a 'recvAio'.
3434
#'
3535
#' If the Aio operation is yet to complete, the result will be an
3636
#' 'unresolved value', which is a logical NA. Once complete, the resolved
@@ -131,45 +131,44 @@ stop_aio <- function(aio) {
131131

132132
}
133133

134-
#' Is Resolved (Asynchronous AIO Operation)
134+
#' Query if an Aio is Unresolved
135135
#'
136-
#' Query whether an Aio or Aio value has resolved. This function is non-blocking
136+
#' Query whether an Aio or Aio value is unresolved. This function is non-blocking
137137
#' unlike \code{\link{call_aio}} which waits for completion.
138138
#'
139139
#' @param aio An Aio (object of class 'sendAio' or 'recvAio'), or Aio value
140140
#' stored in \code{$result}, \code{$raw} or \code{$data} as the case may be.
141141
#'
142142
#' @return Logical TRUE or FALSE.
143143
#'
144-
#' @details Returns FALSE only for unresolved nanonext Aios or Aio values; returns
145-
#' TRUE in all other cases and for all other objects.
144+
#' @details Returns TRUE for unresolved nanonext Aios or Aio values; returns
145+
#' FALSE in all other cases and for all other objects.
146146
#'
147147
#' Note: querying resolution may cause a previously unresolved Aio to resolve.
148148
#'
149149
#' @examples
150150
#' s1 <- socket("pair", listen = "inproc://nanonext")
151151
#' aio <- send_aio(s1, "test", timeout = 100)
152-
#' is_resolved(aio)
153152
#'
154-
#' s2 <- socket("pair", dial = "inproc://nanonext")
155-
#' is_resolved(aio)
153+
#' while (unresolved(aio)) {
154+
#' print(unresolved(aio))
155+
#' s2 <- socket("pair", dial = "inproc://nanonext")
156+
#' Sys.sleep(0.01)
157+
#' }
158+
#'
159+
#' unresolved(aio)
156160
#'
157161
#' close(s1)
158162
#' close(s2)
159163
#'
160164
#' @export
161165
#'
162-
is_resolved <- function(aio) {
166+
unresolved <- function(aio) {
163167

164-
if (inherits(aio, "recvAio")) {
165-
!inherits(.subset2(aio, "data"), "unresolvedValue")
166-
} else if (inherits(aio, "sendAio")) {
167-
!inherits(.subset2(aio, "result"), "unresolvedValue")
168-
} else if (inherits(aio, "unresolvedValue")) {
169-
FALSE
170-
} else {
171-
TRUE
172-
}
168+
{inherits(aio, "unresolvedValue") ||
169+
inherits(aio, "recvAio") && inherits(.subset2(aio, "data"), "unresolvedValue") ||
170+
inherits(aio, "sendAio") && inherits(.subset2(aio, "result"), "unresolvedValue")} &&
171+
return(TRUE)
173172

174173
}
175174

R/listdial.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ dial <- function(socket,
8383
}
8484
if (logging()) {
8585
cat(format.POSIXct(Sys.time()), "[ dial start ] sock:",
86-
attr(res, "socket"), "| url:", url, "\n")
86+
attr(res, "socket"), "| url:", url, "\n", file = stdout())
8787
}
8888
} else {
8989
res <- .Call(rnng_dialer_create, .subset2(socket, "socket"), url)
@@ -112,7 +112,7 @@ dial <- function(socket,
112112
}
113113
if (logging()) {
114114
cat(format.POSIXct(Sys.time()), "[ dial start ] sock:",
115-
attr(res, "socket"), "| url:", url, "\n")
115+
attr(res, "socket"), "| url:", url, "\n", file = stdout())
116116
}
117117
} else {
118118
res <- .Call(rnng_dialer_create, socket, url)
@@ -212,7 +212,7 @@ listen <- function(socket,
212212
}
213213
if (logging()) {
214214
cat(format.POSIXct(Sys.time()), "[ list start ] sock:",
215-
attr(res, "socket"), "| url:", url, "\n")
215+
attr(res, "socket"), "| url:", url, "\n", file = stdout())
216216
}
217217
} else {
218218
res <- .Call(rnng_listener_create, .subset2(socket, "socket"), url)
@@ -241,7 +241,7 @@ listen <- function(socket,
241241
}
242242
if (logging()) {
243243
cat(format.POSIXct(Sys.time()), "[ list start ] sock:",
244-
attr(res, "socket"), "| url:", url, "\n")
244+
attr(res, "socket"), "| url:", url, "\n", file = stdout())
245245
}
246246
} else {
247247
res <- .Call(rnng_listener_create, socket, url)

R/methods.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ start.nanoListener <- function(x, ...) {
3131
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
3232
} else if (logging()) {
3333
cat(format.POSIXct(Sys.time()), "[ list start ] sock:",
34-
attr(x, "socket"), "| url:", attr(x, "url"), "\n")
34+
attr(x, "socket"), "| url:", attr(x, "url"), "\n", file = stdout())
3535
}
3636
invisible(xc)
3737

@@ -48,7 +48,7 @@ start.nanoDialer <- function(x, async = TRUE, ...) {
4848
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
4949
} else if (logging()) {
5050
cat(format.POSIXct(Sys.time()), "[ dial start ] sock:",
51-
attr(x, "socket"), "| url:", attr(x, "url"), "\n")
51+
attr(x, "socket"), "| url:", attr(x, "url"), "\n", file = stdout())
5252
}
5353
invisible(xc)
5454

@@ -94,7 +94,7 @@ close.nanoSocket <- function(con, ...) {
9494
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
9595
} else if (logging()) {
9696
cat(format.POSIXct(Sys.time()), "[ sock close ] id:",
97-
attr(con, "id"), "| protocol:", attr(con, "protocol"), "\n")
97+
attr(con, "id"), "| protocol:", attr(con, "protocol"), "\n", file = stdout())
9898
}
9999
invisible(xc)
100100

@@ -111,7 +111,7 @@ close.nanoContext <- function(con, ...) {
111111
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
112112
} else if (logging()) {
113113
cat(format.POSIXct(Sys.time()), "[ ctxt close ] id:",
114-
attr(con, "id"), "| sock:", attr(con, "socket"), "\n")
114+
attr(con, "id"), "| sock:", attr(con, "socket"), "\n", file = stdout())
115115
}
116116
invisible(xc)
117117

@@ -128,7 +128,7 @@ close.nanoDialer <- function(con, ...) {
128128
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
129129
} else if (logging()) {
130130
cat(format.POSIXct(Sys.time()), "[ dial start ] sock:",
131-
attr(con, "socket"), "| url:", attr(con, "url"), "\n")
131+
attr(con, "socket"), "| url:", attr(con, "url"), "\n", file = stdout())
132132
}
133133

134134
invisible(xc)
@@ -146,7 +146,7 @@ close.nanoListener <- function(con, ...) {
146146
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
147147
} else if (logging()) {
148148
cat(format.POSIXct(Sys.time()), "[ list close ] sock:",
149-
attr(con, "socket"), "| url:", attr(con, "url"), "\n")
149+
attr(con, "socket"), "| url:", attr(con, "url"), "\n", file = stdout())
150150
}
151151

152152
invisible(xc)

R/nano.R

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ print.nanoObject <- function(x, ...) {
148148

149149
cat("< nano object >\n - socket id:", attr(.subset2(x, "socket"), "id"),
150150
"\n - state:", attr(.subset2(x, "socket"), "state"),
151-
"\n - protocol:", attr(.subset2(x, "socket"), "protocol"), "\n")
151+
"\n - protocol:", attr(.subset2(x, "socket"), "protocol"), "\n", file = stdout())
152152
if (!is.null(.subset2(x, "listener")))
153-
cat(" - listener:", unlist(lapply(.subset2(x, "listener"), attr, "url")), sep = "\n ")
153+
cat(" - listener:", unlist(lapply(.subset2(x, "listener"), attr, "url")),
154+
sep = "\n ", file = stdout())
154155
if (!is.null(.subset2(x, "dialer")))
155-
cat(" - dialer:", unlist(lapply(.subset2(x, "dialer"), attr, "url")), sep = "\n ")
156+
cat(" - dialer:", unlist(lapply(.subset2(x, "dialer"), attr, "url")),
157+
sep = "\n ", file = stdout())
156158
invisible(x)
157159

158160
}
@@ -163,11 +165,13 @@ print.nanoSocket <- function(x, ...) {
163165

164166
cat("< nanoSocket >\n - id:", attr(x, "id"),
165167
"\n - state:", attr(x, "state"),
166-
"\n - protocol:", attr(x, "protocol"), "\n")
168+
"\n - protocol:", attr(x, "protocol"), "\n", file = stdout())
167169
if (!is.null(attr(x, "listener")))
168-
cat(" - listener:", unlist(lapply(attr(x, "listener"), attr, "url")), sep = "\n ")
170+
cat(" - listener:", unlist(lapply(attr(x, "listener"), attr, "url")),
171+
sep = "\n ", file = stdout())
169172
if (!is.null(attr(x, "dialer")))
170-
cat(" - dialer:", unlist(lapply(attr(x, "dialer"), attr, "url")), sep = "\n ")
173+
cat(" - dialer:", unlist(lapply(attr(x, "dialer"), attr, "url")),
174+
sep = "\n ", file = stdout())
171175
invisible(x)
172176

173177
}
@@ -179,7 +183,7 @@ print.nanoContext <- function(x, ...) {
179183
cat("< nanoContext >\n - id:", attr(x, "id"),
180184
"\n - socket:", attr(x, "socket"),
181185
"\n - state:", attr(x, "state"),
182-
"\n - protocol:", attr(x, "protocol"), "\n")
186+
"\n - protocol:", attr(x, "protocol"), "\n", file = stdout())
183187
invisible(x)
184188

185189
}
@@ -191,7 +195,7 @@ print.nanoDialer <- function(x, ...) {
191195
cat("< nanoDialer >\n - id:", attr(x, "id"),
192196
"\n - socket:", attr(x, "socket"),
193197
"\n - state:", attr(x, "state"),
194-
"\n - url:", attr(x, "url"), "\n")
198+
"\n - url:", attr(x, "url"), "\n", file = stdout())
195199
invisible(x)
196200

197201
}
@@ -203,7 +207,7 @@ print.nanoListener <- function(x, ...) {
203207
cat("< nanoListener >\n - id:", attr(x, "id"),
204208
"\n - socket:", attr(x, "socket"),
205209
"\n - state:", attr(x, "state"),
206-
"\n - url:", attr(x, "url"), "\n")
210+
"\n - url:", attr(x, "url"), "\n", file = stdout())
207211
invisible(x)
208212

209213
}
@@ -212,7 +216,7 @@ print.nanoListener <- function(x, ...) {
212216
#'
213217
print.recvAio <- function(x, ...) {
214218

215-
cat("< recvAio >\n - $raw for raw message\n - $data for message data\n")
219+
cat("< recvAio >\n - $raw for raw message\n - $data for message data\n", file = stdout())
216220
invisible(x)
217221

218222
}
@@ -221,7 +225,7 @@ print.recvAio <- function(x, ...) {
221225
#'
222226
print.sendAio <- function(x, ...) {
223227

224-
cat("< sendAio >\n - $result for send result\n")
228+
cat("< sendAio >\n - $result for send result\n", file = stdout())
225229
invisible(x)
226230

227231
}
@@ -262,7 +266,7 @@ print.sendAio <- function(x, ...) {
262266
#'
263267
print.unresolvedValue <- function(x, ...) {
264268

265-
cat("< unresolved value >\n")
269+
cat("< unresolved value >\n", file = stdout())
266270
invisible(x)
267271

268272
}

R/socket.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ socket <- function(protocol = c("pair", "bus", "push", "pull", "req", "rep",
6868
message(Sys.time(), " [ ", res, " ] ", nng_error(res))
6969
} else if (logging()) {
7070
cat(format.POSIXct(Sys.time()), "[ sock open ] id:",
71-
attr(res, "id"), "| protocol:", attr(res, "protocol"), "\n")
71+
attr(res, "id"), "| protocol:", attr(res, "protocol"), "\n", file = stdout())
7272
}
7373
if (!missing(dial)) {
7474
dial(res, url = dial, autostart = autostart)
@@ -123,7 +123,7 @@ subscribe <- function(socket, topic = NULL) {
123123
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
124124
} else if (logging()) {
125125
cat(format.POSIXct(Sys.time()), "[ subscribe ] sock:", attr(socket, "id"),
126-
"| topic:", if (is.null(topic)) "ALL" else topic, "\n")
126+
"| topic:", if (is.null(topic)) "ALL" else topic, "\n", file = stdout())
127127
}
128128
invisible(xc)
129129

@@ -176,7 +176,7 @@ unsubscribe <- function(socket, topic = NULL) {
176176
message(Sys.time(), " [ ", xc, " ] ", nng_error(xc))
177177
} else if (logging()) {
178178
cat(format.POSIXct(Sys.time()), "[ unsubscribe ] sock:", attr(socket, "id"),
179-
"| topic:", if (is.null(topic)) "ALL" else topic, "\n")
179+
"| topic:", if (is.null(topic)) "ALL" else topic, "\n", file = stdout())
180180
}
181181
invisible(xc)
182182

@@ -232,7 +232,7 @@ survey_time <- function(socket, time) {
232232
res <- setopt(socket, type = "ms", opt = "surveyor:survey-time", value = time)
233233
if (logging()) {
234234
cat(format.POSIXct(Sys.time()), "[ survey ] sock:", attr(socket, "id"),
235-
"| set time:", time, "\n")
235+
"| set time:", time, "\n", file = stdout())
236236
}
237237

238238
}

R/utils.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ logging <- function(level) {
109109
cache <<- switch(level,
110110
error = 0L,
111111
info = 1L)
112-
cat(format.POSIXct(Sys.time()), "[ logging level ] set to:", level, "\n")
112+
cat(format.POSIXct(Sys.time()), "[ log level ] set to:", level,
113+
"\n", file = stdout())
113114

114115
}
115116

man/call_aio.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)