| 59 | } |
| 60 | |
| 61 | void AndroidDispatchQueue::scheduleFlush(std::chrono::steady_clock::duration delay) { |
| 62 | // TODO(simon): We could avoid scheduling a flush for every tasks. |
| 63 | |
| 64 | auto finish = std::chrono::steady_clock::now() + delay; |
| 65 | auto* self = Valdi::unsafeRetain(this); |
| 66 | auto* cb = new Valdi::DispatchFunction([self, finish]() { |
| 67 | auto remaining = finish - std::chrono::steady_clock::now(); |
| 68 | if (remaining.count() > 0) { |
| 69 | self->scheduleFlush(remaining); |
| 70 | } else { |
| 71 | self->flush(); |
| 72 | } |
| 73 | Valdi::unsafeRelease(self); |
| 74 | }); |
| 75 | |
| 76 | int64_t delayMs = std::chrono::duration_cast<std::chrono::milliseconds>(delay).count(); |
| 77 | if (delayMs == 0) { |
| 78 | _dispatcher->dispatch(cb, false); |
| 79 | } else { |
| 80 | _dispatcher->dispatchAfter(delayMs, cb); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void AndroidDispatchQueue::flush() { |
| 85 | if (!_mainThreadId.has_value()) { |
nothing calls this directly
no test coverage detected