Skip to content

Commit

Permalink
Merge pull request #211 from HongjiangHuang/chore/custome-apitimeout
Browse files Browse the repository at this point in the history
feat: Custome api timeout support
  • Loading branch information
weakish authored Jun 29, 2020
2 parents 445cd22 + 7b7da13 commit 750ccf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/LeanCloud/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public static function initialize($appId, $appKey, $appMasterKey) {
Role::registerClass();
}

/**
* Set a deadline for requests to complete.
*
* Note that file upload requests are not affected.
*
* @param integer $seconds
*/
public static function setApiTimeout($seconds) {
static::$apiTimeout = intval($seconds);
}

/**
* Assert client is correctly initialized
*
Expand Down
9 changes: 9 additions & 0 deletions test/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,14 @@ public function testGzipCompatibility() {
Client::delete("/classes/TestObject/{$resp['objectId']}");
}

public function testRequestTimeout() {
$getTimeout = function() { return static::$apiTimeout; };
$getApiTimeout = $getTimeout->bindTo(null, Client::class);
$this->assertEquals(15, $getApiTimeout());
Client::setApiTimeout(3);
$this->assertEquals(3, $getApiTimeout());
Client::setApiTimeout(15); // revert to default
}

}

0 comments on commit 750ccf7

Please sign in to comment.