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
isClosedForSend
should never returntrue
in the callback, but this is only because in the theawaitClose
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 whenisClosedForSend
isfalse
a subsequentoffer
call might still throw and hence in thesafeOffer
function we still need to wrap a try / catch aroundoffer
.Hope that answered your question 😀