Skip to content

Commit ca8b6d9

Browse files
committed
improve: remove parallel no wait publisher as it is a bad design
1 parent 5cabef3 commit ca8b6d9

File tree

2 files changed

+0
-41
lines changed

2 files changed

+0
-41
lines changed

projects/kediatr-core/src/main/kotlin/com/trendyol/kediatr/PublishStrategies.kt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ interface PublishStrategy {
3030
*/
3131
val CONTINUE_ON_EXCEPTION: PublishStrategy = ContinueOnExceptionPublishStrategy()
3232

33-
/**
34-
* Publish strategy that executes handlers in parallel without waiting for completion.
35-
*/
36-
val PARALLEL_NO_WAIT: PublishStrategy = ParallelNoWaitPublishStrategy()
37-
3833
/**
3934
* Publish strategy that executes handlers in parallel and waits for all to complete.
4035
*/
@@ -91,28 +86,6 @@ interface PublishStrategy {
9186
) = withContext(dispatcher) { notificationHandlers.forEach { it.handle(notification) } }
9287
}
9388

94-
/**
95-
* Publish strategy that executes all handlers in parallel without waiting for completion.
96-
* This is a "fire-and-forget" approach where the publish method returns immediately
97-
* after launching all handler coroutines.
98-
*/
99-
class ParallelNoWaitPublishStrategy : PublishStrategy {
100-
/**
101-
* Publishes the notification to all handlers in parallel without waiting for completion.
102-
* Each handler is launched in its own coroutine and the method returns immediately.
103-
*
104-
* @param T The type of notification to publish
105-
* @param notification The notification instance to publish
106-
* @param notificationHandlers Collection of handlers that will process the notification
107-
* @param dispatcher The coroutine dispatcher to use for execution
108-
*/
109-
override suspend fun <T : Notification> publish(
110-
notification: T,
111-
notificationHandlers: Collection<NotificationHandler<T>>,
112-
dispatcher: CoroutineDispatcher
113-
) = withContext(dispatcher) { notificationHandlers.forEach { launch { it.handle(notification) } } }
114-
}
115-
11689
/**
11790
* Publish strategy that executes all handlers in parallel and waits for all to complete.
11891
* If any handler throws an exception, it will be propagated after all handlers have completed.

projects/kediatr-core/src/testFixtures/kotlin/com/trendyol/kediatr/testing/MediatorUseCases.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -489,20 +489,6 @@ abstract class MediatorUseCases : MediatorTestConvention() {
489489
exception.exceptions.map { it::class }.toSet() shouldBe setOf(RuntimeException::class, IllegalStateException::class)
490490
}
491491

492-
@Test
493-
fun slow_notification_with_parallel_no_wait_strategy_should_return_immediately() = runTest {
494-
val notification = SlowNotification(100)
495-
val startTime = System.currentTimeMillis()
496-
497-
testMediator.publish(notification, PublishStrategy.PARALLEL_NO_WAIT)
498-
499-
val endTime = System.currentTimeMillis()
500-
val executionTime = endTime - startTime
501-
502-
// Should return quickly without waiting for handlers - allow more variance for CI environments
503-
executionTime shouldBeLessThan 500
504-
}
505-
506492
@Test
507493
fun slow_notification_with_parallel_when_all_strategy_should_wait_for_all_handlers() = runTest {
508494
val notification = SlowNotification(500)

0 commit comments

Comments
 (0)