-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlushDeferredEvents.php
More file actions
46 lines (39 loc) · 1.15 KB
/
FlushDeferredEvents.php
File metadata and controls
46 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* Copyright 2025 Cloud Creativity Limited
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
declare(strict_types=1);
namespace CloudCreativity\Modules\Application\InboundEventBus\Middleware;
use Closure;
use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher;
use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware;
use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent;
use Throwable;
final readonly class FlushDeferredEvents implements InboundEventMiddleware
{
/**
* FlushDeferredEvents constructor.
*
* @param DeferredDispatcher $dispatcher
*/
public function __construct(private DeferredDispatcher $dispatcher)
{
}
/**
* @inheritDoc
*/
public function __invoke(IntegrationEvent $event, Closure $next): void
{
try {
$next($event);
} catch (Throwable $ex) {
$this->dispatcher->forget();
throw $ex;
}
$this->dispatcher->flush();
}
}