mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
Kernel: Add DeviceManagement::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
064b93c2ad
commit
da5d678f2a
2 changed files with 10 additions and 0 deletions
|
@ -109,6 +109,15 @@ void DeviceManagement::for_each(Function<void(Device&)> callback)
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<void> DeviceManagement::try_for_each(Function<ErrorOr<void>(Device&)> callback)
|
||||
{
|
||||
return m_devices.with([&](auto& map) -> ErrorOr<void> {
|
||||
for (auto& entry : map)
|
||||
TRY(callback(*entry.value));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
NullDevice& DeviceManagement::null_device()
|
||||
{
|
||||
return *m_null_device;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue