rfc:retry-keyword
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:retry-keyword [2017/06/19 13:32] – Fix type-o's and stupid tabs sammyk | rfc:retry-keyword [2017/07/03 15:17] – Update target PHP version to PHP 7.3 sammyk | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Retry keyword in catch blocks | + | ====== PHP RFC: Retry functionality |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2016-06-19 | * Date: 2016-06-19 | ||
Line 135: | Line 135: | ||
</ | </ | ||
- | This is arguably the cleanest option | + | While this is arguably the cleanest option, it still requires |
+ | |||
+ | <code php> | ||
+ | $maxTries = 5; | ||
+ | |||
+ | retryTheThing: | ||
+ | |||
+ | someCodeIDoNotWantToRetry(); | ||
+ | |||
+ | try { | ||
+ | somethingSketchy(); | ||
+ | } catch (RecoverableException $e) { | ||
+ | if (--$maxTries > 0) { | ||
+ | goto retryTheThing; | ||
+ | } | ||
+ | die(' | ||
+ | } | ||
+ | </ | ||
==== Use Retry ==== | ==== Use Retry ==== | ||
Line 156: | Line 173: | ||
</ | </ | ||
- | Alternatively using the block-level implementation of '' | + | Alternatively using the block-level implementation of '' |
<code php> | <code php> | ||
Line 232: | Line 249: | ||
=== Breaking out of retry === | === Breaking out of retry === | ||
- | It is sometimes necessary to have some logic that would abort any more retry attempts, like in the case of retrying forever. That can be done using the ``break`` keyword. | + | It is sometimes necessary to have some logic that would abort any more retry attempts, like in the case of retrying forever. That can be done using the '' |
<code php> | <code php> | ||
Line 361: | Line 378: | ||
===== Proposed PHP Version ===== | ===== Proposed PHP Version ===== | ||
- | Next PHP 7.2. | + | Next PHP 7.3. |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Requires a 2/3 majority. | Requires a 2/3 majority. | ||
+ | |||
+ | ==== Add block-level retry ==== | ||
+ | |||
+ | <code php> | ||
+ | try { | ||
+ | somethingSketchy(); | ||
+ | } retry 3 (RecoverableException $e, $attempt) { | ||
+ | sleep(1); | ||
+ | } catch (RecoverableException $e) { | ||
+ | echo $e-> | ||
+ | } | ||
+ | </ | ||
<doodle title=" | <doodle title=" | ||
Line 371: | Line 400: | ||
* No | * No | ||
</ | </ | ||
+ | |||
+ | ==== Add retry keyword ==== | ||
+ | |||
+ | <code php> | ||
+ | try { | ||
+ | somethingSketchy(); | ||
+ | } catch (RecoverableException $e) | ||
+ | retry; | ||
+ | } | ||
+ | </ | ||
<doodle title=" | <doodle title=" |
rfc/retry-keyword.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1