File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55use Exception ;
66use gipfl \Cli \Screen ;
77use Icinga \Module \Vspheredb \Clicommands \Command ;
8+ use Icinga \Module \Vspheredb \Daemon \PromiseUtil ;
89use Icinga \Module \Vspheredb \Data \Anonymizer ;
910use InvalidArgumentException ;
1011use React \Promise \PromiseInterface ;
@@ -72,14 +73,17 @@ protected function run($callable)
7273 }
7374
7475 if ($ result instanceof PromiseInterface) {
75- $ result ->then (function () {
76- // All done
77- }, function (Exception $ e ) {
78- $ this ->addProblem ('UNKNOWN ' , $ e ->getMessage ());
79- $ this ->showOptionalTrace ($ e );
80- })->finally (function () {
81- $ this ->shutdown ();
82- });
76+ PromiseUtil::finally (
77+ $ result ->then (function () {
78+ // All done
79+ }, function (Exception $ e ) {
80+ $ this ->addProblem ('UNKNOWN ' , $ e ->getMessage ());
81+ $ this ->showOptionalTrace ($ e );
82+ }),
83+ function () {
84+ $ this ->shutdown ();
85+ }
86+ );
8387 } else {
8488 $ this ->shutdown ();
8589 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Icinga \Module \Vspheredb \Daemon ;
4+
5+ use React \Promise \PromiseInterface ;
6+
7+ /**
8+ * ReactPHP Promise compatibility helpers
9+ */
10+ class PromiseUtil
11+ {
12+ /**
13+ * Register cleanup on ReactPHP Promise v2 and v3 promises
14+ *
15+ * @param PromiseInterface $promise Promise to register cleanup on
16+ * @param callable $callback Callback receiving no arguments
17+ *
18+ * @return PromiseInterface
19+ */
20+ public static function finally (PromiseInterface $ promise , callable $ callback ): PromiseInterface
21+ {
22+ if (method_exists ($ promise , 'finally ' )) {
23+ return $ promise ->finally ($ callback );
24+ }
25+
26+ return $ promise ->always ($ callback );
27+ }
28+ }
Original file line number Diff line number Diff line change 22
33namespace Icinga \Module \Vspheredb \Monitoring ;
44
5+ use Icinga \Module \Vspheredb \Daemon \PromiseUtil ;
6+
57class CheckPlugin
68{
79 /** @var array */
@@ -31,15 +33,18 @@ protected function run($callable)
3133 }
3234
3335 if ($ result instanceof PromiseInterface) {
34- $ result ->then (function () {
35- echo "as \n" ;
36- }, function (Exception $ e ) {
37- var_dump ('whut ' );
38- $ this ->addProblem ('UNKNOWN ' , $ e ->getMessage ());
39- })->finally (function () {
40- var_dump ('Shut after res ' );
41- $ this ->shutdown ();
42- });
36+ PromiseUtil::finally (
37+ $ result ->then (function () {
38+ echo "as \n" ;
39+ }, function (Exception $ e ) {
40+ var_dump ('whut ' );
41+ $ this ->addProblem ('UNKNOWN ' , $ e ->getMessage ());
42+ }),
43+ function () {
44+ var_dump ('Shut after res ' );
45+ $ this ->shutdown ();
46+ }
47+ );
4348 } else {
4449 $ this ->shutdown ();
4550 }
You can’t perform that action at this time.
0 commit comments