mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
LibCore: Slightly rework the Core::Promise API
The previous iteration of this API was somewhat odd and rough in random places, which degraded usability and made less than perfect sense. This commit reworks the API to be a little closer to more conventional promise APIs (a la javascript promises). Also adds a test to ensure the class even works.
This commit is contained in:
parent
5a0ad6812c
commit
0c5c75e8a4
9 changed files with 150 additions and 38 deletions
|
@ -76,7 +76,7 @@ void ThreadEventQueue::cancel_all_pending_jobs()
|
|||
{
|
||||
Threading::MutexLocker lock(m_private->mutex);
|
||||
for (auto const& promise : m_private->pending_promises)
|
||||
promise->cancel(Error::from_errno(ECANCELED));
|
||||
promise->reject(Error::from_errno(ECANCELED));
|
||||
|
||||
m_private->pending_promises.clear();
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ size_t ThreadEventQueue::process()
|
|||
{
|
||||
Threading::MutexLocker locker(m_private->mutex);
|
||||
events = move(m_private->queued_events);
|
||||
m_private->pending_promises.remove_all_matching([](auto& job) { return job->is_resolved() || job->is_canceled(); });
|
||||
m_private->pending_promises.remove_all_matching([](auto& job) { return job->is_resolved() || job->is_rejected(); });
|
||||
}
|
||||
|
||||
size_t processed_events = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue