mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
Kernel: Add Process::try_for_each_thread() for fallible iteration
This API will allow users to short circuit iteration and properly propagate errors.
This commit is contained in:
parent
f4875b9967
commit
aca6c0c031
1 changed files with 10 additions and 0 deletions
|
@ -237,6 +237,7 @@ public:
|
|||
IterationDecision for_each_thread(Callback);
|
||||
template<IteratorFunction<Thread&> Callback>
|
||||
IterationDecision for_each_thread(Callback callback) const;
|
||||
ErrorOr<void> try_for_each_thread(Function<ErrorOr<void>(Thread const&)>) const;
|
||||
|
||||
// Non-breakable iteration functions
|
||||
template<VoidFunction<Process&> Callback>
|
||||
|
@ -939,6 +940,15 @@ inline IterationDecision Process::for_each_thread(Callback callback) const
|
|||
return IterationDecision::Continue;
|
||||
}
|
||||
|
||||
inline ErrorOr<void> Process::try_for_each_thread(Function<ErrorOr<void>(Thread const&)> callback) const
|
||||
{
|
||||
return thread_list().with([&](auto& thread_list) -> ErrorOr<void> {
|
||||
for (auto& thread : thread_list)
|
||||
TRY(callback(thread));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
template<VoidFunction<Thread&> Callback>
|
||||
inline IterationDecision Process::for_each_thread(Callback callback)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue