Skip to content

Commit

Permalink
call_aio_ and wait_
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Nov 21, 2023
1 parent 8e9e093 commit b602702
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nanonext
Type: Package
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
Version: 0.10.4.9007
Version: 0.10.4.9008
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
a socket library implementing 'Scalability Protocols', a reliable,
high-performance standard for common communications patterns including
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export(.until)
export(base64dec)
export(base64enc)
export(call_aio)
export(call_safe)
export(call_aio_)
export(context)
export(cv)
export(cv_reset)
Expand Down Expand Up @@ -99,7 +99,7 @@ export(unresolved)
export(unsubscribe)
export(until)
export(wait)
export(wait_safe)
export(wait_)
export(write_cert)
importFrom(stats,start)
importFrom(utils,.DollarNames)
Expand Down
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# nanonext 0.10.4.9007 (development)
# nanonext 0.10.4.9008 (development)

#### New Features

* Introduces `call_safe()`, a safe user-interruptible version of `call_aio()` suitable for interactive use.
* Introduces `wait_safe()`, a safe user-interruptible version of `wait()` suitable for interactive use.
* Introduces `call_aio_()`, a safe user-interruptible version of `call_aio()` suitable for interactive use.
* Introduces `wait_()`, a safe user-interruptible version of `wait()` suitable for interactive use.
* Implements `%~>%` signal forwarder from one 'conditionVariable' to another.

#### Updates
Expand Down
6 changes: 3 additions & 3 deletions R/aio.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ recv_aio_signal <- function(con,
#'
#' msg <- recv_aio(s2, timeout = 100)
#' msg
#' call_safe(msg)$data
#' call_aio_(msg)$data
#'
#' close(s1)
#' close(s2)
Expand All @@ -221,13 +221,13 @@ call_aio <- function(aio) invisible(.Call(rnng_aio_call, aio))

#' Call the Value of an Asynchronous Aio Operation
#'
#' \code{call_safe} is identical to \code{call_aio} but allows user
#' \code{call_aio_} is identical to \code{call_aio} but allows user
#' interrupts, thus being safe for interactive use.
#'
#' @rdname call_aio
#' @export
#'
call_safe <- function(aio) invisible(.Call(rnng_wait_thread_create, aio))
call_aio_ <- function(aio) invisible(.Call(rnng_wait_thread_create, aio))

#' Stop Asynchronous Aio Operation
#'
Expand Down
6 changes: 3 additions & 3 deletions R/sync.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ cv <- function() .Call(rnng_cv_alloc)
#'
#' @examples
#' # wait(cv) # uncommenting will block until the cv is signalled
#' # wait_safe(cv) # block until the cv is signalled or interrupted
#' # wait_(cv) # block until the cv is signalled or interrupted
#'
#' @rdname cv
#' @export
Expand All @@ -94,13 +94,13 @@ wait <- function(cv) invisible(.Call(rnng_cv_wait, cv))

#' Condition Variables - Wait Safe
#'
#' \code{wait_safe} is identical to \code{wait} but allows user interrupts, thus
#' \code{wait_} is identical to \code{wait} but allows user interrupts, thus
#' being safe for interactive use.
#'
#' @rdname cv
#' @export
#'
wait_safe <- function(cv) invisible(.Call(rnng_cv_wait_safe, cv))
wait_ <- function(cv) invisible(.Call(rnng_cv_wait_safe, cv))

#' Condition Variables - Until
#'
Expand Down
8 changes: 4 additions & 4 deletions man/call_aio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/cv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ nanotesterr(msg$data, "active")
nanotest(identical(call_aio(n), n))
nanotestaio(sraio <- n$send_aio(as.raw(0L), mode = "r", timeout = 500))
nanotestaio(rraio <- n1$recv_aio(mode = 1L, timeout = 500))
nanotestw(is_nul_byte(call_safe(rraio)$data))
nanotestw(is_nul_byte(call_aio_(rraio)$data))
nanotestaio(sraio <- n$send_aio(as.raw(1L), mode = "ra", timeout = 500))
nanotestaio(rraio <- n1$recv_aio(mode = "raw", timeout = 500))
nanotest(is.raw(call_aio(rraio)$data))
Expand Down Expand Up @@ -188,7 +188,7 @@ nanotesterr(req$opt("false", list()), "type")
nanotestnano(ctx <- context(rep))
nanotestp(ctx)
nanotestaio(csaio <- req$send_aio(data.frame(), mode = "seria", timeout = 500))
nanotest(is.integer(call_safe(csaio)$result))
nanotest(is.integer(call_aio_(csaio)$result))
nanotestaio(craio <- recv_aio(ctx, timeout = 500))
nanotest(is.list(.subset2(call_aio(craio), "data")))
nanotest(is.integer(req$send("context test", mode ="raw", block = 500)))
Expand Down Expand Up @@ -247,7 +247,7 @@ nanotesterr(recv_aio_signal(err, cv = cv, timeout = 500))
nanotesterr(request_signal(.context(req$socket), "test", cv = err), "valid")
nanotesterr(recv_aio_signal(rep, "test", cv = err), "valid")
nanotesterr(wait(err), "valid")
nanotesterr(wait_safe(err), "valid")
nanotesterr(wait_(err), "valid")
nanotesterr(until(err, 10), "valid")
nanotesterr(cv_value(err), "valid")
nanotesterr(cv_reset(err), "valid")
Expand Down Expand Up @@ -292,7 +292,7 @@ nanotestxp(cv3 <- cv())
nanotestxp(cv %~>% cv2 %~>% cv3)
nanotestz(cv_signal(cv))
nanotest(cv_value(cv) == 1L)
nanotest(wait_safe(cv3))
nanotest(wait_(cv3))

nanotestnano(surv <- nano(protocol = "surveyor", listen = "inproc://sock1", dial = "inproc://sock2"))
nanotestp(surv)
Expand Down Expand Up @@ -342,7 +342,7 @@ nanotest(is.integer(call_aio(haio)$status))
haio <- ncurl_aio("https://trin.cam.ac.uk/", convert = FALSE, response = list("server"))
nanotest(is.integer(call_aio(haio)$status))
put1 <- ncurl_aio("http://postman-echo.com/put", method = "PUT", headers = c(Authorization = "Bearer token"), data = "test", response = c("date", "server"), timeout = 3000L)
nanotest(is.integer(call_safe(put1)$status))
nanotest(is.integer(call_aio_(put1)$status))
nanotestnn(put1$headers)
nanotestnn(put1$data)
put2 <- ncurl_aio("http://postman-echo.com/put", method = "PUT", headers = list(Authorization = "Bearer token"), response = list("date", "server"), timeout = 3000L)
Expand Down Expand Up @@ -414,7 +414,7 @@ if (length(s)) {
nanotestn(stop_aio(ss))
nanotest(is.integer(send(s, 12.56, mode = "raw", block = 500L)))
nanotestaio(sr <- recv_aio_signal(s, mode = "double", timeout = 500L, cv = cv))
nanotestw(length(call_safe(sr)[["data"]]))
nanotestw(length(call_aio_(sr)[["data"]]))
nanotest(cv_value(cv) > 0L)
nanotest(wait(cv))
nanotest(is.character(opt(s, "ws:request-headers")))
Expand Down Expand Up @@ -492,7 +492,7 @@ unres <- `class<-`(NA, "unresolvedValue")
nanotest(!unresolved(unres))
nanotestp(unres)
nanotest(identical(call_aio("a"), "a"))
nanotest(identical(call_safe("a"), "a"))
nanotest(identical(call_aio_("a"), "a"))
nanotestn(stop_aio("a"))

nanotest(sha256("test") == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
Expand Down

0 comments on commit b602702

Please sign in to comment.