Yew: Send `Destroy` and `Disconnected` messages when PrivateBridge drops

Created on 12 Feb 2020  路  6Comments  路  Source: yewstack/yew

Problem

Private workers are not destroyed properly because Destroy messages are not sent when a PrivateBridge is dropped.

https://github.com/yewstack/yew/blob/1ede16795a8f08975708e1808c0d528f31d5c946/src/agent.rs#L481

Proposed Solution

Copy public worker solution. Make it DRY if possible

bug good first issue

All 6 comments

I've started to look into this issue and wanted your input on how to solve this. Would we have to replicate the same model used for public agents where they're stored inside an agent pool as we have on https://github.com/yewstack/yew/blob/5491bf99ccb1970da6a6dc3fbc6647604e7a9b62/yew/src/agent.rs#L573 ?

Nope, no need because private agents are only connected to from a single client and so there's a one to one mapping from client to agent and only a single bridge involved. Public agents can be connected to from multiple clients at the same time and so REMOTE_AGENTS_POOL is a mechanism for clients to discover an already existing agent when creating additional bridges.

The key part for this issue is here:
https://github.com/yewstack/yew/blob/a91e7f651253382ac9abafb5ca2e0e0df669cd2c/yew/src/agent.rs#L741-L746

Thanks for the tip, @jstarry. In that case I'd need to add an ID to the private bridge, given that it currently has no ID and the Disconnected message has an ID attached to it.

To make things simple, given the 1:1 relation, would it be ok to just send an arbitrary ID like 0 or would I have to use something like a static counter to guarantee that the ID is unique always?

0 is fine! I guess that's probably why Connected and Disconnected were never implemented 馃槤

Speaking of which, while you're at it can you fix: https://github.com/yewstack/yew/issues/948? It's very related

@joaquindk oh we already have this actually, SINGLETON_ID

Perfect, I鈥檒l also take care of #948 in that case 鈽猴笍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sackery picture sackery  路  3Comments

sanpii picture sanpii  路  3Comments

alun picture alun  路  4Comments

kellytk picture kellytk  路  4Comments

IngwiePhoenix picture IngwiePhoenix  路  4Comments