Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!Send impl for various reader types #256

Open
weiznich opened this issue Jan 17, 2022 · 4 comments
Open

!Send impl for various reader types #256

weiznich opened this issue Jan 17, 2022 · 4 comments

Comments

@weiznich
Copy link
Contributor

weiznich commented Jan 17, 2022

Is there any reason why capnp::struct_list::Reader and similar types are not Send? That makes it quite hard to use them in a async context, where each value of those iterator is later used to spawn of a future task.

@tv42
Copy link

tv42 commented Jan 2, 2024

I just stumbled on this. I don't understand why some things would have to be !Send when the TypedReader is okay to send. It seems the *_capnp::foo::Reader just contains raw pointers and ended up being !Send by default. Those should be fine to mark as Send.

See also #180 (comment)

// this is a TypedReader<BufferSegments<&[u8]>, ...> 
let typed_reader = ...;

// the TypedReader is fine to send across await
while let Some(blah) = my_stream.next().await {
    // but the *_capnp::foo::Reader isn't
    // and I have to do this on every iteration
    let foo = typed_reader.get().unwrap();
    ...
}

@tv42
Copy link

tv42 commented Feb 1, 2024

Okay so #479 (comment) points out Readers are not safe to Send because they borrow the underlying buffer. Hmm.

@tv42
Copy link

tv42 commented Feb 1, 2024

In my use case, my data source is (moral equivalent of) Arc<Box<u8>>. It'd be nice to have a Send or Send+Sync Reader when the data source happens to be Send/Sync.

@ozgrakkurt
Copy link

In my use case, my data source is (moral equivalent of) Arc<Box<u8>>. It'd be nice to have a Send or Send+Sync Reader when the data source happens to be Send/Sync.

You can send the buffer over and construct the Reader on the other side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants