Learn R Programming

nanonext (version 1.3.0)

pipe_notify: Pipe Notify

Description

Signals a ‘conditionVariable’ whenever pipes (individual connections) are added or removed at a socket.

Usage

pipe_notify(socket, cv, cv2 = NULL, add = FALSE, remove = FALSE, flag = FALSE)

Value

Invisibly, zero on success (will otherwise error).

Arguments

socket

a Socket.

cv

a ‘conditionVariable’ to signal, or NULL to cancel a previously set signal.

cv2

[default NULL] optionally, if specified, a second ‘conditionVariable’ to signal. Note that this cv is signalled sequentially after the first condition variable.

add

[default FALSE] logical value whether to signal (or cancel signal) when a pipe is added.

remove

[default FALSE] logical value whether to signal (or cancel signal) when a pipe is removed.

flag

[default FALSE] logical value whether to also set a flag in the ‘conditionVariable’. This can help distinguish between different types of signal, and causes any subsequent wait to return FALSE instead of TRUE. If a signal from the tools package, e.g. tools::SIGINT, or an equivalent integer value is supplied, this sets a flag and additionally raises this signal upon the flag being set.

Details

For add: this event occurs after the pipe is fully added to the socket. Prior to this time, it is not possible to communicate over the pipe with the socket.

For remove: this event occurs after the pipe has been removed from the socket. The underlying transport may be closed at this point, and it is not possible to communicate using this pipe.

Examples

Run this code
s <- socket(listen = "inproc://nanopipe")
cv <- cv()
cv2 <- cv()

pipe_notify(s, cv, cv2, add = TRUE, remove = TRUE, flag = TRUE)
cv_value(cv)
cv_value(cv2)

s1 <- socket(dial = "inproc://nanopipe")
cv_value(cv)
cv_value(cv2)
reap(s1)
cv_value(cv)
cv_value(cv2)

pipe_notify(s, NULL, add = TRUE, remove = TRUE)
s1 <- socket(dial = "inproc://nanopipe")
cv_value(cv)
cv_value(cv2)
reap(s1)

(wait(cv))
(wait(cv2))

close(s)

Run the code above in your browser using DataLab