酒店预订平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

364 рядки
9.9 KiB

  1. <?php
  2. namespace GuzzleHttp\Promise;
  3. /**
  4. * Get the global task queue used for promise resolution.
  5. *
  6. * This task queue MUST be run in an event loop in order for promises to be
  7. * settled asynchronously. It will be automatically run when synchronously
  8. * waiting on a promise.
  9. *
  10. * <code>
  11. * while ($eventLoop->isRunning()) {
  12. * GuzzleHttp\Promise\queue()->run();
  13. * }
  14. * </code>
  15. *
  16. * @param TaskQueueInterface $assign Optionally specify a new queue instance.
  17. *
  18. * @return TaskQueueInterface
  19. *
  20. * @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
  21. */
  22. function queue(TaskQueueInterface $assign = null)
  23. {
  24. return Utils::queue($assign);
  25. }
  26. /**
  27. * Adds a function to run in the task queue when it is next `run()` and returns
  28. * a promise that is fulfilled or rejected with the result.
  29. *
  30. * @param callable $task Task function to run.
  31. *
  32. * @return PromiseInterface
  33. *
  34. * @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
  35. */
  36. function task(callable $task)
  37. {
  38. return Utils::task($task);
  39. }
  40. /**
  41. * Creates a promise for a value if the value is not a promise.
  42. *
  43. * @param mixed $value Promise or value.
  44. *
  45. * @return PromiseInterface
  46. *
  47. * @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
  48. */
  49. function promise_for($value)
  50. {
  51. return Create::promiseFor($value);
  52. }
  53. /**
  54. * Creates a rejected promise for a reason if the reason is not a promise. If
  55. * the provided reason is a promise, then it is returned as-is.
  56. *
  57. * @param mixed $reason Promise or reason.
  58. *
  59. * @return PromiseInterface
  60. *
  61. * @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
  62. */
  63. function rejection_for($reason)
  64. {
  65. return Create::rejectionFor($reason);
  66. }
  67. /**
  68. * Create an exception for a rejected promise value.
  69. *
  70. * @param mixed $reason
  71. *
  72. * @return \Exception|\Throwable
  73. *
  74. * @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
  75. */
  76. function exception_for($reason)
  77. {
  78. return Create::exceptionFor($reason);
  79. }
  80. /**
  81. * Returns an iterator for the given value.
  82. *
  83. * @param mixed $value
  84. *
  85. * @return \Iterator
  86. *
  87. * @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
  88. */
  89. function iter_for($value)
  90. {
  91. return Create::iterFor($value);
  92. }
  93. /**
  94. * Synchronously waits on a promise to resolve and returns an inspection state
  95. * array.
  96. *
  97. * Returns a state associative array containing a "state" key mapping to a
  98. * valid promise state. If the state of the promise is "fulfilled", the array
  99. * will contain a "value" key mapping to the fulfilled value of the promise. If
  100. * the promise is rejected, the array will contain a "reason" key mapping to
  101. * the rejection reason of the promise.
  102. *
  103. * @param PromiseInterface $promise Promise or value.
  104. *
  105. * @return array
  106. *
  107. * @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
  108. */
  109. function inspect(PromiseInterface $promise)
  110. {
  111. return Utils::inspect($promise);
  112. }
  113. /**
  114. * Waits on all of the provided promises, but does not unwrap rejected promises
  115. * as thrown exception.
  116. *
  117. * Returns an array of inspection state arrays.
  118. *
  119. * @see inspect for the inspection state array format.
  120. *
  121. * @param PromiseInterface[] $promises Traversable of promises to wait upon.
  122. *
  123. * @return array
  124. *
  125. * @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
  126. */
  127. function inspect_all($promises)
  128. {
  129. return Utils::inspectAll($promises);
  130. }
  131. /**
  132. * Waits on all of the provided promises and returns the fulfilled values.
  133. *
  134. * Returns an array that contains the value of each promise (in the same order
  135. * the promises were provided). An exception is thrown if any of the promises
  136. * are rejected.
  137. *
  138. * @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
  139. *
  140. * @return array
  141. *
  142. * @throws \Exception on error
  143. * @throws \Throwable on error in PHP >=7
  144. *
  145. * @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
  146. */
  147. function unwrap($promises)
  148. {
  149. return Utils::unwrap($promises);
  150. }
  151. /**
  152. * Given an array of promises, return a promise that is fulfilled when all the
  153. * items in the array are fulfilled.
  154. *
  155. * The promise's fulfillment value is an array with fulfillment values at
  156. * respective positions to the original array. If any promise in the array
  157. * rejects, the returned promise is rejected with the rejection reason.
  158. *
  159. * @param mixed $promises Promises or values.
  160. * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.
  161. *
  162. * @return PromiseInterface
  163. *
  164. * @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
  165. */
  166. function all($promises, $recursive = false)
  167. {
  168. return Utils::all($promises, $recursive);
  169. }
  170. /**
  171. * Initiate a competitive race between multiple promises or values (values will
  172. * become immediately fulfilled promises).
  173. *
  174. * When count amount of promises have been fulfilled, the returned promise is
  175. * fulfilled with an array that contains the fulfillment values of the winners
  176. * in order of resolution.
  177. *
  178. * This promise is rejected with a {@see AggregateException} if the number of
  179. * fulfilled promises is less than the desired $count.
  180. *
  181. * @param int $count Total number of promises.
  182. * @param mixed $promises Promises or values.
  183. *
  184. * @return PromiseInterface
  185. *
  186. * @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
  187. */
  188. function some($count, $promises)
  189. {
  190. return Utils::some($count, $promises);
  191. }
  192. /**
  193. * Like some(), with 1 as count. However, if the promise fulfills, the
  194. * fulfillment value is not an array of 1 but the value directly.
  195. *
  196. * @param mixed $promises Promises or values.
  197. *
  198. * @return PromiseInterface
  199. *
  200. * @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
  201. */
  202. function any($promises)
  203. {
  204. return Utils::any($promises);
  205. }
  206. /**
  207. * Returns a promise that is fulfilled when all of the provided promises have
  208. * been fulfilled or rejected.
  209. *
  210. * The returned promise is fulfilled with an array of inspection state arrays.
  211. *
  212. * @see inspect for the inspection state array format.
  213. *
  214. * @param mixed $promises Promises or values.
  215. *
  216. * @return PromiseInterface
  217. *
  218. * @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
  219. */
  220. function settle($promises)
  221. {
  222. return Utils::settle($promises);
  223. }
  224. /**
  225. * Given an iterator that yields promises or values, returns a promise that is
  226. * fulfilled with a null value when the iterator has been consumed or the
  227. * aggregate promise has been fulfilled or rejected.
  228. *
  229. * $onFulfilled is a function that accepts the fulfilled value, iterator index,
  230. * and the aggregate promise. The callback can invoke any necessary side
  231. * effects and choose to resolve or reject the aggregate if needed.
  232. *
  233. * $onRejected is a function that accepts the rejection reason, iterator index,
  234. * and the aggregate promise. The callback can invoke any necessary side
  235. * effects and choose to resolve or reject the aggregate if needed.
  236. *
  237. * @param mixed $iterable Iterator or array to iterate over.
  238. * @param callable $onFulfilled
  239. * @param callable $onRejected
  240. *
  241. * @return PromiseInterface
  242. *
  243. * @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
  244. */
  245. function each(
  246. $iterable,
  247. callable $onFulfilled = null,
  248. callable $onRejected = null
  249. ) {
  250. return Each::of($iterable, $onFulfilled, $onRejected);
  251. }
  252. /**
  253. * Like each, but only allows a certain number of outstanding promises at any
  254. * given time.
  255. *
  256. * $concurrency may be an integer or a function that accepts the number of
  257. * pending promises and returns a numeric concurrency limit value to allow for
  258. * dynamic a concurrency size.
  259. *
  260. * @param mixed $iterable
  261. * @param int|callable $concurrency
  262. * @param callable $onFulfilled
  263. * @param callable $onRejected
  264. *
  265. * @return PromiseInterface
  266. *
  267. * @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
  268. */
  269. function each_limit(
  270. $iterable,
  271. $concurrency,
  272. callable $onFulfilled = null,
  273. callable $onRejected = null
  274. ) {
  275. return Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
  276. }
  277. /**
  278. * Like each_limit, but ensures that no promise in the given $iterable argument
  279. * is rejected. If any promise is rejected, then the aggregate promise is
  280. * rejected with the encountered rejection.
  281. *
  282. * @param mixed $iterable
  283. * @param int|callable $concurrency
  284. * @param callable $onFulfilled
  285. *
  286. * @return PromiseInterface
  287. *
  288. * @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
  289. */
  290. function each_limit_all(
  291. $iterable,
  292. $concurrency,
  293. callable $onFulfilled = null
  294. ) {
  295. return Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
  296. }
  297. /**
  298. * Returns true if a promise is fulfilled.
  299. *
  300. * @return bool
  301. *
  302. * @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
  303. */
  304. function is_fulfilled(PromiseInterface $promise)
  305. {
  306. return Is::fulfilled($promise);
  307. }
  308. /**
  309. * Returns true if a promise is rejected.
  310. *
  311. * @return bool
  312. *
  313. * @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
  314. */
  315. function is_rejected(PromiseInterface $promise)
  316. {
  317. return Is::rejected($promise);
  318. }
  319. /**
  320. * Returns true if a promise is fulfilled or rejected.
  321. *
  322. * @return bool
  323. *
  324. * @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
  325. */
  326. function is_settled(PromiseInterface $promise)
  327. {
  328. return Is::settled($promise);
  329. }
  330. /**
  331. * Create a new coroutine.
  332. *
  333. * @see Coroutine
  334. *
  335. * @return PromiseInterface
  336. *
  337. * @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
  338. */
  339. function coroutine(callable $generatorFn)
  340. {
  341. return Coroutine::of($generatorFn);
  342. }