-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be90bca
commit c6c5cf1
Showing
16 changed files
with
323 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package port | ||
|
||
// CloseHook is an interface that defines a method for handling resource cleanup. | ||
type CloseHook interface { | ||
// Close performs the necessary cleanup actions. | ||
Close() | ||
} | ||
|
||
// CloseHooks represents a slice of CloseHook interfaces, which are processed in reverse order when closed. | ||
type CloseHooks []CloseHook | ||
|
||
type closeHook struct { | ||
close func() | ||
} | ||
|
||
var _ CloseHook = (CloseHooks)(nil) | ||
var _ CloseHook = (*closeHook)(nil) | ||
|
||
// CloseHookFunc creates a new CloseHook from the provided function. | ||
func CloseHookFunc(fn func()) CloseHook { | ||
return &closeHook{close: fn} | ||
} | ||
|
||
func (h CloseHooks) Close() { | ||
for i := len(h) - 1; i >= 0; i-- { | ||
hook := h[i] | ||
hook.Close() | ||
} | ||
} | ||
|
||
func (h *closeHook) Close() { | ||
h.close() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.