Yeah had a few problems with the smart

Yeah had a few problems with the smart pointers a while ago as well. But I'll give it another go. My problem right now though is that I can't call self from within the event handler.
8 Replies
radix
radix•15mo ago
is "self" here the actual durable object?
Samuel
SamuelOP•15mo ago
Yup. Here's the struct for self. #[durable_object] pub struct Server{ network: Network, state: State, env: Env, }
radix
radix•15mo ago
ok, so what I ended up doing is basically keeping my equivalent of Network wrapped in Rc<RefCell<Network>>, and then passing a clone of that into my event handler
radix
radix•15mo ago
GitHub
arpeggiorpg/worker/src/durablegame.rs at main · radix/arpeggiorpg
A tabletop role-playing game system. Contribute to radix/arpeggiorpg development by creating an account on GitHub.
radix
radix•15mo ago
(there's still a lot I need to do on how I maintain the websockets -- I'm not yet cleaning them up when they disconnect, but the general idea is there & works)
radix
radix•15mo ago
I created a separate struct in "wsrpi.rs" that is responsible for handling a single connection, and it has a clone of that Rc<RefCell<Network>>, and that's where my "broadcast" method lives: https://github.com/radix/arpeggiorpg/blob/main/worker/src/wsrpi.rs#L269
GitHub
arpeggiorpg/worker/src/wsrpi.rs at main · radix/arpeggiorpg
A tabletop role-playing game system. Contribute to radix/arpeggiorpg development by creating an account on GitHub.
Samuel
SamuelOP•15mo ago
Genius. Looking into it right now! Thanks. @radix I'm finding that
Response::from_websocket(client)
Response::from_websocket(client)
for some reason evokes this panic"called Result::unwrap() on an Err value: JsValue(RangeError: Responses may only be constructed with status codes in the range 200 to 599, inclusive." Any clue as to why? I mean I get that it returns a 101 that's what it's supposed to return for websockets right? Nevermind it works. Was a version issue.
radix
radix•15mo ago
oh, interesting. I was going to say, that sounds really strange 🙂 glad you got it working.
Want results from more Discord servers?
Add your server