mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 07:07:23 +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:
committed by
Andreas Kling
parent
74ab8ccde0
commit
24be52b3f5
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user