MadelineProtoDocs/docs/PHPInternal/danog/MadelineProto/Coroutine.md

98 lines
2.0 KiB
Markdown
Raw Normal View History

2020-10-15 18:42:54 +02:00
---
title: danog\MadelineProto\Coroutine: Creates a promise from a generator function yielding promises.
description: When a promise is yielded, execution of the generator is interrupted until the promise is resolved. A success
value is sent into the generator, while a failure reason is thrown into the generator. Using a coroutine,
asynchronous code can be written without callbacks and be structured like synchronous code.
---
# `danog\MadelineProto\Coroutine`
[Back to index](../../index.md)
> Author: Daniil Gentili <daniil@daniil.it>
Creates a promise from a generator function yielding promises.
When a promise is yielded, execution of the generator is interrupted until the promise is resolved. A success
value is sent into the generator, while a failure reason is thrown into the generator. Using a coroutine,
asynchronous code can be written without callbacks and be structured like synchronous code.
## Method list:
* `fail(\Throwable $reason): void`
* `offsetGet(mixed $offset): \Amp\Promise`
* `getTrace(): array`
* `getFrame(): array`
* `jsonSerialize(): string`
* `onResolve()`
## Methods:
### `fail(\Throwable $reason): void`
Parameters:
* `$reason`: `\Throwable` Failure reason.
#### See also:
* `\Throwable`
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
### `offsetGet(mixed $offset): \Amp\Promise`
Get data at an array offset asynchronously.
Parameters:
* `$offset`: `mixed` Offset
#### See also:
* `\Amp\Promise`
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
### `getTrace(): array`
Get current stack trace for running coroutine.
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
### `getFrame(): array`
Get current execution frame.
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
### `jsonSerialize(): string`
Obtain.
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
### `onResolve()`
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)
2020-10-15 18:42:54 +02:00
2020-10-15 19:11:10 +02:00
---
Generated by [danog/phpdoc](https://phpdoc.daniil.it)