mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03: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
Notes:
sideshowbarker
2024-07-17 18:10:17 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/da5d678f2a Pull-request: https://github.com/SerenityOS/serenity/pull/12754 Reviewed-by: https://github.com/bgianfo ✅ Reviewed-by: https://github.com/elcuco
@ -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;
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
void before_device_removal(Badge<Device>, Device&);
|
||||
|
||||
void for_each(Function<void(Device&)>);
|
||||
ErrorOr<void> try_for_each(Function<ErrorOr<void>(Device&)>);
|
||||
Device* get_device(MajorNumber major, MinorNumber minor);
|
||||
|
||||
NullDevice const& null_device() const;
|
||||
|
Loading…
Reference in New Issue
Block a user