From 9d9af68d103c44799cebcc499914056d7af67d01 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 3 Feb 2024 23:16:46 +0700 Subject: [PATCH] MailboxExecutorService docs --- .../ru/dbotthepony/kommons/util/MailboxExecutorService.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/kommons/util/MailboxExecutorService.kt b/src/main/kotlin/ru/dbotthepony/kommons/util/MailboxExecutorService.kt index b5c8aa3..c13b5e6 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/util/MailboxExecutorService.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/util/MailboxExecutorService.kt @@ -36,6 +36,12 @@ private fun > LinkedList.enqueue(value: E) { } } +/** + * [ScheduledExecutorService] which act as a mailbox, [executeQueuedTasks] must be called from main thread. + * + * [submit], [execute], etc can be called on any thread. If any of enqueueing methods are called on the same thread + * as where [executeQueuedTasks] was called, executes provided lambda immediately and returns completed future. + */ class MailboxExecutorService(thread: Thread = Thread.currentThread()) : ScheduledExecutorService { @Volatile var thread: Thread = thread