File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,23 @@ class GearmanConsumer implements Consumer
25
25
*/
26
26
private $ context ;
27
27
28
+ /**
29
+ * Message content.
30
+ *
31
+ * @var mixed
32
+ */
33
+ private $ message ;
34
+
28
35
public function __construct (GearmanContext $ context , GearmanDestination $ destination )
29
36
{
30
37
$ this ->context = $ context ;
31
38
$ this ->destination = $ destination ;
32
39
33
40
$ this ->worker = $ context ->createWorker ();
41
+
42
+ $ this ->worker ->addFunction ($ this ->destination ->getName (), function (\GearmanJob $ job ) {
43
+ $ this ->message = GearmanMessage::jsonUnserialize ($ job ->workload ());
44
+ });
34
45
}
35
46
36
47
/**
@@ -53,18 +64,14 @@ public function receive(int $timeout = 0): ?Message
53
64
$ this ->worker ->setTimeout ($ timeout );
54
65
55
66
try {
56
- $ message = null ;
57
-
58
- $ this ->worker ->addFunction ($ this ->destination ->getName (), function (\GearmanJob $ job ) use (&$ message ) {
59
- $ message = GearmanMessage::jsonUnserialize ($ job ->workload ());
60
- });
67
+ $ this ->message = null ;
61
68
62
69
$ this ->worker ->work ();
63
70
} finally {
64
71
restore_error_handler ();
65
72
}
66
73
67
- return $ message ;
74
+ return $ this -> message ;
68
75
}
69
76
70
77
/**
You can’t perform that action at this time.
0 commit comments