This is a part of #59 originally developed by @VictorLowther
Original description from #59:
Change the Shutdown() routine to use Context-based cancellation.
This avoids a couple of initialization order based races, and gets
rid of the need to pass channels of channels around.
Get rid of handler GC stuff in favor of immediate handler cleanup
under a mutex. This gets rid of the confusing recover based retry
logic for handling the case where GC has not happened yet is no
longer needed, since you don't need additional GC logic if you don't
leak garbage in the first place. That there is no longer a chance
for stack exhaustion vis recursive calls to the parent function in
the recover path is just an added bonus.
NB: This is only a part of original #59, another commit on top of this one is required to get rid of the race conditions.
This is a part of #59 originally developed by @VictorLowther
Original description from #59:
Change the Shutdown() routine to use Context-based cancellation. This avoids a couple of initialization order based races, and gets rid of the need to pass channels of channels around.
Get rid of handler GC stuff in favor of immediate handler cleanup under a mutex. This gets rid of the confusing recover based retry logic for handling the case where GC has not happened yet is no longer needed, since you don't need additional GC logic if you don't leak garbage in the first place. That there is no longer a chance for stack exhaustion vis recursive calls to the parent function in the recover path is just an added bonus.
NB: This is only a part of original #59, another commit on top of this one is required to get rid of the race conditions.