@@ -81,12 +81,13 @@ pub const Loop = struct {
8181
8282 // run tail events. We do run the tail events to ensure all the
8383 // contexts are correcly free.
84- while (self .hasPendinEvents () ) {
85- self .io .run_for_ns (10 * std .time .ns_per_ms ) catch | err | {
84+ while (self .pending_network_count != 0 or self . pending_timeout_count != 0 ) {
85+ self .io .run_for_ns (std .time .ns_per_ms * 10 ) catch | err | {
8686 log .err (.loop , "deinit" , .{ .err = err });
8787 break ;
8888 };
8989 }
90+
9091 if (comptime CANCEL_SUPPORTED ) {
9192 self .io .cancel_all ();
9293 }
@@ -96,21 +97,6 @@ pub const Loop = struct {
9697 self .cancelled .deinit (self .alloc );
9798 }
9899
99- // We can shutdown once all the pending network IO is complete.
100- // In debug mode we also wait until al the pending timeouts are complete
101- // but we only do this so that the `timeoutCallback` can free all allocated
102- // memory and we won't report a leak.
103- fn hasPendinEvents (self : * const Self ) bool {
104- if (self .pending_network_count > 0 ) {
105- return true ;
106- }
107-
108- if (builtin .mode != .Debug ) {
109- return false ;
110- }
111- return self .pending_timeout_count > 0 ;
112- }
113-
114100 // Retrieve all registred I/O events completed by OS kernel,
115101 // and execute sequentially their callbacks.
116102 // Stops when there is no more I/O events registered on the loop.
@@ -121,9 +107,11 @@ pub const Loop = struct {
121107 self .stopping = true ;
122108 defer self .stopping = false ;
123109
124- while (self .pending_network_count > 0 ) {
125- try self .io .run_for_ns (10 * std .time .ns_per_ms );
126- // at each iteration we might have new events registred by previous callbacks
110+ while (self .pending_network_count != 0 or self .pending_timeout_count != 0 ) {
111+ self .io .run_for_ns (std .time .ns_per_ms * 10 ) catch | err | {
112+ log .err (.loop , "deinit" , .{ .err = err });
113+ break ;
114+ };
127115 }
128116 }
129117
0 commit comments