only-cliches / NoProto

Flexible, Fast & Compact Serialization with RPC
MIT License
374 stars 14 forks source link

Send and NP_Factory #5

Closed User65k closed 4 years ago

User65k commented 4 years ago

Hi, I try to use NoProto and Sled as a simple DB and figured it would make sense to parse the Schema only once. However, its all across an async code base and the inserts and updates would come only after some awaits happened. This is seems to be a roadblock with NoProto, as NP_Factory is not Send.

I basically

  1. start a Server
  2. create a NP_Factory
  3. wait for IO to happen
  4. want to store that IO

Compiling my simple PoC gives me:

error: future cannot be sent between threads safely
   --> src/main.rs:82:38
    |
82  |     let server = Server::bind(&addr).serve(make_service);
    |                                      ^^^^^ future returned by `proxy` is not `Send`
    |
    = help: within `no_proto::NP_Factory`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<no_proto::schema::NP_Schema>`
note: future is not `Send` as this value is used across an await

I guess an Arc instead of an Rc (in NP_Factory and NP_SchemaKinds) would solve it. Or am I doing it wrong?

only-cliches commented 4 years ago

Hey thanks for the issue, happy to see interest so quickly in my project!

I've reworked the library to remove all reference counting, should be good to Send now.

Make sure you grab version 0.2.1 or greater.