@@ -18,9 +18,9 @@ class SleepyThread extends \Thread{
1818 /** @var \Threaded */
1919 private $buffer;
2020
21- public function __construct(\pocketmine\snooze\SleeperNotifier $notifier){
21+ public function __construct(\pocketmine\snooze\SleeperNotifier $notifier, \Threaded $buffer ){
2222 $this->notifier = $notifier;
23- $this->buffer = new \Threaded() ;
23+ $this->buffer = $buffer ;
2424 }
2525
2626 public function run() : void{
@@ -40,19 +40,16 @@ class SleepyThread extends \Thread{
4040 $this->notifier->wakeupSleeper();
4141 }
4242 }
43-
44- public function getLineFromBuffer() : ?string{
45- return $this->buffer->shift();
46- }
4743}
4844
4945$sleeper = new \pocketmine\snooze\SleeperHandler();
5046
5147$notifier = new \pocketmine\snooze\SleeperNotifier();
52- $thread = new SleepyThread($notifier);
53- $sleeper->addNotifier($notifier, function() use($thread) : void{
48+ $buffer = new \Threaded();
49+ $thread = new SleepyThread($notifier, $buffer);
50+ $sleeper->addNotifier($notifier, function() use($buffer) : void{
5451 //do some things when this notifier sends a notification
55- echo "Main thread got line: " . $thread->getLineFromBuffer ();
52+ echo "Main thread got line: " . $buffer->shift ();
5653});
5754
5855//don't start the thread until we add the notifier, otherwise we could get unexpected behaviour (race conditions)
0 commit comments