mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
Kernel: Add LocalSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly propagate errors.
This commit is contained in:
parent
74ab8ccde0
commit
24be52b3f5
2 changed files with 10 additions and 0 deletions
|
@ -34,6 +34,15 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<void> LocalSocket::try_for_each(Function<ErrorOr<void>(const LocalSocket&)> callback)
|
||||
{
|
||||
return all_sockets().with_shared([&](const auto& sockets) -> ErrorOr<void> {
|
||||
for (auto& socket : sockets)
|
||||
TRY(callback(socket));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
|
||||
{
|
||||
auto client_buffer = TRY(DoubleBuffer::try_create());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue