mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-20 06:36:16 +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:
committed by
Linus Groh
parent
5a0ad6812c
commit
0c5c75e8a4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user