Skip to content

Commit

Permalink
Add timeouts to receive() and transmit()
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 6, 2024
1 parent a14c9ca commit 83a7453
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ OpenAI APIs for XP ChangeLog

## ?.?.? / ????-??-??

* Added optional parameter *timeout* to receive() and transmit() methods
(@thekid)

## 0.8.0 / 2024-11-02

* Made it possible to supply organization and project in OpenAI API URI
Expand Down
10 changes: 6 additions & 4 deletions src/main/php/com/openai/realtime/RealtimeApi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ public function send($payload): void {
/**
* Receives an answer. Returns NULL if EOF is reached.
*
* @param ?int|float $timeout
* @return var
*/
public function receive() {
$json= $this->ws->receive();
public function receive($timeout= null) {
$json= $this->ws->receive($timeout);
$this->cat && $this->cat->debug('<<<', $json);
return null === $json ? null : $this->marshalling->unmarshal(Json::read($json));
}
Expand All @@ -110,11 +111,12 @@ public function receive() {
* Sends a given payload and returns the response to it.
*
* @param var $payload
* @param ?int|float $timeout
* @return var
*/
public function transmit($payload) {
public function transmit($payload, $timeout= null) {
$this->send($payload);
return $this->receive();
return $this->receive($timeout);
}

/** Ensures socket is closed */
Expand Down

0 comments on commit 83a7453

Please sign in to comment.