Skip to content

Commit 2bac632

Browse files
dfalbellionel-
andauthored
Add a method to query a unique session id (#759)
* Add a method to query a unique session id * Update crates/ark/src/reticulate.rs Co-authored-by: Lionel Henry <[email protected]> * Use LazyLock --------- Co-authored-by: Lionel Henry <[email protected]>
1 parent b037c6d commit 2bac632

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/ark/src/modules/positron/reticulate.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@
127127
}
128128
)
129129
}
130+
131+
#' @export
132+
.ps.rpc.reticulate_id <- function() {
133+
.ps.Call("ps_reticulate_id")
134+
}

crates/ark/src/reticulate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ use crate::interface::RMain;
2222
static RETICULATE_OUTGOING_TX: LazyLock<Mutex<Option<Sender<CommMsg>>>> =
2323
LazyLock::new(|| Mutex::new(None));
2424

25+
// Each ark session has a unique session id which is used by the Positron frontend
26+
// to associate a client id with a session.
27+
static RETICULATE_ID: LazyLock<String> =
28+
LazyLock::new(|| format!("reticulate-{}", Uuid::new_v4().to_string()));
29+
2530
#[derive(Clone)]
2631
pub struct ReticulateService {
2732
comm: CommSocket,
@@ -53,7 +58,8 @@ impl ReticulateService {
5358
let event = CommManagerEvent::Opened(
5459
service.comm.clone(),
5560
json!({
56-
"input": input
61+
"input": input,
62+
"reticulate_id": (*RETICULATE_ID).clone(),
5763
}),
5864
);
5965
service
@@ -137,3 +143,8 @@ pub unsafe extern "C-unwind" fn ps_reticulate_open(input: SEXP) -> Result<SEXP,
137143

138144
Ok(R_NilValue)
139145
}
146+
147+
#[harp::register]
148+
pub unsafe extern "C-unwind" fn ps_reticulate_id() -> Result<SEXP, anyhow::Error> {
149+
Ok(RObject::from((*RETICULATE_ID).clone()).sexp)
150+
}

0 commit comments

Comments
 (0)