Skip to content

Commit 02aca17

Browse files
committed
std/internal/poll: minor refactoring for error handling in Poll.Close
1 parent d4197fd commit 02aca17

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

std/internal/poll/fd_unix.jule

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,15 @@ impl FD {
435435
self.pd.evict()
436436
}
437437

438+
defer {
439+
// Wait until the descriptor is closed. If this was the only
440+
// reference, it is already closed.
441+
semacquire(&self.csema).await
442+
}
443+
438444
// The call to decref will call destroy if there are no other
439445
// references.
440-
let mut err: any
441-
self.decref() else { err = error }
442-
443-
// Wait until the descriptor is closed. If this was the only
444-
// reference, it is already closed.
445-
semacquire(&self.csema).await
446-
447-
if err != nil {
448-
throw err
449-
}
446+
self.decref()?
450447
}
451448
}
452449

std/internal/poll/fd_windows.jule

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,16 @@ impl FD {
624624
if self.pollable && self.pd != nil {
625625
self.pd.evict()
626626
}
627-
let mut err: any
628-
self.decref() else { err = error }
629-
// Wait until the descriptor is closed. If this was the only
630-
// reference, it is already closed.
631-
semacquire(&self.csema).await
632-
if err != nil {
633-
throw err
627+
628+
defer {
629+
// Wait until the descriptor is closed. If this was the only
630+
// reference, it is already closed.
631+
semacquire(&self.csema).await
634632
}
633+
634+
// The call to decref will call destroy if there are no other
635+
// references.
636+
self.decref()?
635637
}
636638

637639
// Waits for cancellation.

0 commit comments

Comments
 (0)