changed pollForMessages() impl

This commit is contained in:
Ben Menking
2026-05-09 14:34:47 -04:00
parent 9f44882aa7
commit d053f7e3eb
3 changed files with 19 additions and 10 deletions
+12 -5
View File
@@ -301,26 +301,33 @@ class Meshcore {
}
/**
* Poll for messages, returning after timeout or if a message with <tag> is received. This function can
* return zero to many results in an array. Not all messages may match <tag>.
*
* @param string $tag
* @param int $timeout_ms
* @return mixed
* @param int $timeout_ms defaults to 5 seconds
* @return array
*/
public function pollForMessage(string $tag, int $timeout_ms = 5000): mixed {
public function pollForMessage(string $tag, int $timeout_ms = 5000): array {
$mark = time();
$messages = [];
do {
$msg = self::getNextMessage();
if( $msg instanceof BinaryResponse ) {
$messages[] = $msg;
}
if( $msg instanceof BinaryResponse && $msg->tag == $tag ) {
return $msg;
return $messages;
}
usleep(500000);
}
while( ((time() - $mark) * 1000) < $timeout_ms );
return false;
return $messages;
}
}