-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from swoft-cloud/feature
modify result
- Loading branch information
Showing
8 changed files
with
98 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Swoft\Core; | ||
|
||
use Swoft\Pool\ConnectionInterface; | ||
|
||
/** | ||
* AbstractResult | ||
*/ | ||
abstract class AbstractResult implements ResultInterface | ||
{ | ||
/** | ||
* @var ConnectionInterface | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $profileKey; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $result; | ||
|
||
/** | ||
* AbstractCorResult constructor. | ||
* | ||
* @param mixed $result | ||
* @param mixed $connection | ||
* @param string $profileKey | ||
*/ | ||
public function __construct($result, $connection = null, string $profileKey = '') | ||
{ | ||
$this->result = $result; | ||
$this->connection = $connection; | ||
$this->profileKey = $profileKey; | ||
} | ||
|
||
/** | ||
* Receive by defer | ||
* | ||
* @param bool $defer | ||
* @param bool $release | ||
* | ||
* @return mixed | ||
*/ | ||
protected function recv(bool $defer = false, bool $release = true) | ||
{ | ||
if ($this->connection instanceof ConnectionInterface) { | ||
$result = $this->connection->receive(); | ||
$this->release($release); | ||
|
||
return $result; | ||
} | ||
|
||
$result = $this->connection->recv(); | ||
if ($defer) { | ||
$this->connection->setDefer(false); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @param bool $release | ||
*/ | ||
protected function release(bool $release = true) | ||
{ | ||
if ($this->connection instanceof ConnectionInterface && $release) { | ||
$this->connection->release(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters