@@ -15,27 +15,39 @@ class Scheduler
15
15
16
16
public static function getDefault (): SchedulerInterface
17
17
{
18
- if (! static ::$ default ) {
19
- static ::$ default = new EventLoopScheduler () ;
18
+ if (static ::$ default ) {
19
+ return static ::$ default ;
20
20
}
21
21
22
- return static ::$ default ;
22
+ throw new \Exception (
23
+ "Please set a default scheduler (for react: Scheduler::setDefault(new EventLoopScheduler( \$loop)); "
24
+ );
23
25
}
24
26
25
27
public static function setDefault (SchedulerInterface $ scheduler )
26
28
{
27
29
if (static ::$ default !== null ) {
28
- throw new \Exception ("Scheduler can only be set once. (Are you calling set after get?) " );
30
+ throw new \Exception ("Scheduler can only be set once. " );
29
31
}
32
+
30
33
static ::$ default = $ scheduler ;
31
34
}
32
35
33
- public static function getAsync (): SchedulerInterface
36
+ public static function getAsync (): AsyncSchedulerInterface
34
37
{
35
- if (! static ::$ async ) {
36
- static ::$ async = new EventLoopScheduler () ;
38
+ if (static ::$ async ) {
39
+ return static ::$ async ;
37
40
}
38
- return self ::$ async ;
41
+
42
+ if (static ::$ default instanceof AsyncSchedulerInterface) {
43
+ static ::$ async = static ::$ default ;
44
+
45
+ return static ::$ async ;
46
+ }
47
+
48
+ throw new \Exception (
49
+ "Please set an async scheduler (for react: Scheduler::setAsync(new EventLoopScheduler( \$loop)); "
50
+ );
39
51
}
40
52
41
53
public static function getImmediate (): ImmediateScheduler
@@ -46,18 +58,18 @@ public static function getImmediate(): ImmediateScheduler
46
58
return self ::$ immediate ;
47
59
}
48
60
49
- public static function setAsync ($ async )
61
+ public static function setAsync (AsyncSchedulerInterface $ async )
50
62
{
51
63
if (static ::$ async !== null ) {
52
- throw new \Exception ("Scheduler can only be set once. (Are you calling set after get?) " );
64
+ throw new \Exception ("Scheduler can only be set once. " );
53
65
}
54
66
self ::$ async = $ async ;
55
67
}
56
68
57
- public static function setImmediate ($ immediate )
69
+ public static function setImmediate (SchedulerInterface $ immediate )
58
70
{
59
71
if (static ::$ immediate !== null ) {
60
- throw new \Exception ("Scheduler can only be set once. (Are you calling set after get?) " );
72
+ throw new \Exception ("Scheduler can only be set once. " );
61
73
}
62
74
self ::$ immediate = $ immediate ;
63
75
}
0 commit comments