Closed stevenliebregt closed 1 year ago
The issue is that repo
is borrowing from repo_wrapper
. When a value is put in a JsBox
, ownership is transferred to the JavaScript runtime and you can only get references afterwards.
The typical pattern in Rust
for this is to wrap the value in an Arc
.
As far as I see I can't make this work with Neon, I tried looking at the gzip-stream
example, but that uses Clone
which I can't use as the underlying connection also isn't cloneable.
That's what reference counting like an Arc does. It makes it cloneable (cloning increments the counter instead of copying the struct).
I feel like I'm not clear enough on what my problem exactly is, but I have a hard time explaining it.
The Repo
has a postgres::Client
and has a method fn query_many_stream(&mut self) -> Result<postgres::RowIter, Error>
this RowIter
has a lifetime 'a
to the connection.
I have a hard time seeing what part exactly I should wrap in a Mutex, any help is much appreciated.
After you return the value it is managed by the JS VM. The result must be 'static
. If RowIter
borrows from something, it is not compatible and you need to refactor your code to avoid this non-static lifetime.
You could maybe consider moving the connection with the stream using some of the crates enabling self-referential structs.
Hi, I'm not sure how exactly to word this, so I hope the example below makes it clearer.
I'm trying to build a wrapper around a rust database client that uses postgres under the hood. But I'm having some lifetime troubles.
The specific case I'm struggling with is returning an async stream.
The problem however is that the JsFunction is a
Fn
closure, so I can't call next ondata
. And the following lifetime problem:Is what I'm trying to do even possible?