Great question! You're right that in this case isClosedForSend should never return true in the callback, but this is only because in the the awaitClose block we've unregistered / removed the callback from the widget. So this is somewhat a "defensive" approach to make sure we don't crash if we forgot to unregister the callback (which is arguably worse as we usually want to fail early but that's a different conversation).
SendChannel.offer also has other issues (note the 3rd point), so even when isClosedForSend is false a subsequent offer call might still throw and hence in the safeOffer function we still need to wrap a try / catch around offer.
Hope that answered your question 😀
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great question! You're right that in this case
isClosedForSendshould never returntruein the callback, but this is only because in the theawaitCloseblock we've unregistered / removed the callback from the widget. So this is somewhat a "defensive" approach to make sure we don't crash if we forgot to unregister the callback (which is arguably worse as we usually want to fail early but that's a different conversation).SendChannel.offeralso has other issues (note the 3rd point), so even whenisClosedForSendisfalsea subsequentoffercall might still throw and hence in thesafeOfferfunction we still need to wrap a try / catch aroundoffer.Hope that answered your question 😀