esp-rs / esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
https://docs.esp-rs.org/esp-idf-svc/
Apache License 2.0
333 stars 183 forks source link

Invert the logic of Channel and Receiver #371

Closed embediver closed 8 months ago

embediver commented 9 months ago

Previously Receiver held a Weak<Channel>, now Channel holds a Weak<Receiver>. The Receiver now holds the Condvar and State. Also Receiver becomes a Arc<Receiver>.

By this the Channel can be dropped while the Receiver is waiting.

embediver commented 9 months ago

After thinking about this approach for a while, I'm not so sure anymore that its the correct way to solve the Bug.

While the Bug we had is solved, now the Problem is just shifted to the user, which can easily crash his application. Now when a Receiver (e.g. the MqttConnection) is dropped, the same infinite block we had, can happen to the Channel when it is waiting to share a value at that moment. While its not likely that this happens for the most usecases, it would be a pain to debug if it were to happen.

370 solves the problem for both directions and might therefore be the better solution.

The Channel is still public though, in my opinion its better to make it private and use the channel only with QuitOnDrop by providing a function which creates a new channel and returns a QuitOnDrop and a Receiver.

embediver commented 9 months ago

@ivmarkov Do you have other opinions or should this PR be closed?