Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support templating types for static analyse tools like psalm for Channel class #42

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/swoole/Swoole/Coroutine/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Swoole\Coroutine;

/**
* @template T
* @not-serializable Objects of this class cannot be serialized.
* @alias This class has two aliases: \chan and \Co\Channel (when directive "swoole.use_shortname" is not explicitly turned off).
* @see \chan
Expand Down Expand Up @@ -45,7 +46,7 @@ public function __construct(int $size = 1)
/**
* Push an element into the channel.
*
* @param mixed $data The element to be pushed into the channel. It's allowed to be any type of value. However, to avoid any confusion, it's recommended not to use empty values like 0, 0.0, false, ' ', null, etc.
* @param T $data The element to be pushed into the channel. It's allowed to be any type of value. However, to avoid any confusion, it's recommended not to use empty values like 0, 0.0, false, ' ', null, etc.
* @param float $timeout > 0 means waiting for the specified number of seconds. other means no waiting.
* @return bool TRUE on success. If failed, return FALSE and set the error code ($this->errCode) with a non-zero value.
*/
Expand All @@ -59,7 +60,7 @@ public function push(mixed $data, float $timeout = -1): bool
* This pop operation works in a FIFO (first-in-first-out) manner, since elements in the channel are stored in a queue but not a stack.
*
* @param float $timeout > 0 means waiting for the specified number of seconds. other means no waiting.
* @return mixed Remove an element from the front end of the channel, and return the element back. If failed, return FALSE and set the error code ($this->errCode) with a non-zero value.
* @return T|false Remove an element from the front end of the channel, and return the element back. If failed, return FALSE and set the error code ($this->errCode) with a non-zero value.
*/
public function pop(float $timeout = -1): mixed
{
Expand Down