Vapm
  • About
    • Why is it called unblocking?
    • Next update?
    • Credit
    • Info
  • System
    • runEventLoop()
    • runSingleEventLoop()
    • setTimeout()
    • setInterval()
    • fetch()
    • read()
    • time() & timeEnd()
  • Asynchronous
    • getId()
    • await()
  • Promise
    • c()
    • getId()
    • getFiber()
    • isJustGetResult()
    • getTimeOut()
    • getTimeStart()
    • getTimeEnd()
    • setTimeEnd()
    • canDrop()
    • getStatus()
    • getResult()
    • getReturn()
    • getCallback()
    • resolve() & reject()
    • then() & catch() & finally()
    • useCallbacks()
    • all()
    • allSettled()
    • any()
    • race()
    • Some common methods
  • CoroutineGen
    • runBlocking()
    • runNonBlocking()
    • Deferred
    • Deferred Await All
    • repeat() & delay()
    • Channel
      • Example about Channel
    • AwaitGroup
      • Example
    • Mutex
      • Example
    • Goroutine vs CoroutineGen
      • Concurrency
  • Thread
    • How do I create a thread?
    • How do I share data between threads?
    • Advanced Thread
  • Worker
    • Example
  • Stream
    • read()
    • write()
    • append()
    • delete()
    • create()
    • overWrite()
  • FAQ
    • Why System::runEventLoop() and System::runSingleEventLoop() ?
    • Do you want concurrency?
  • PocketMine-PMMP
Powered by GitBook
On this page

Promise

Let's take a look at its interface.

/**
 * @throws Throwable
 *
 * This method is used to create a new promise.
 */
public static function c(callable $callback, bool $justGetResult = false): Promise;

/**
 * This method is used to get the id of the promise.
 */
public function getId(): int;

/**
 * This method is used to get the fiber of the promise.
 */
public function getFiber(): Fiber;

/**
 * This method is used to check if the promise is just to get the result.
 */
public function isJustGetResult(): bool;

/**
 * This method is used to get the time out of the promise.
 */
public function getTimeOut(): float;

/**
 * This method is used to get the time start of the promise.
 */
public function getTimeStart(): float;

/**
 * This method is used to get the time end of the promise.
 */
public function getTimeEnd(): float;

/**
 * This method is used to set the time out of the promise.
 */
public function setTimeEnd(float $timeEnd): void;

/**
 * This method is used to check if the promise is timed out and can be dropped.
 */
public function canDrop(): bool;

/**
 * This method is used to get the status of the promise.
 */
public function getStatus(): string;

/**
 * This method is used to check if the promise is pending.
 */
public function isPending(): bool;

/**
 * This method is used to check if the promise is resolved.
 */
public function isResolved(): bool;

/**
 * This method is used to check if the promise is rejected.
 */
public function isRejected(): bool;

/**
 * This method is used to get the result of the promise.
 */
public function getResult(): mixed;

/**
 * This method is used to get the return when catch or then of the promise is resolved or rejected.
 */
public function getReturn(): mixed;

/**
 * @throws Throwable
 *
 * This method is used to get the callback of the promise.
 */
public function getCallback(): callable;

/**
 * This method is used to resolve the promise.
 */
public function resolve(mixed $value = ''): void;

/**
 * This method is used to reject the promise.
 */
public function reject(mixed $value = ''): void;

/**
 * This method is used to set the callback when the promise is resolved.
 */
public function then(callable $callback): Promise;

/**
 * This method is used to set the callback when the promise is rejected.
 */
public function catch(callable $callback): Promise;

/**
 * This method is used to set the callback when the promise is resolved or rejected.
 */
public function finally(callable $callback): Promise;

/**
 * @throws Throwable
 *
 * This method is used to use the callbacks of the promise.
 */
public function useCallbacks(): void;

/**
 * @throws Throwable
 * @param array<int, Async|Promise|callable> $promises
 * @phpstan-param array<int, Async|Promise|callable> $promises
 */
public static function all(array $promises): Promise;

/**
 * @throws Throwable
 * @param array<int, Async|Promise|callable> $promises
 * @phpstan-param array<int, Async|Promise|callable> $promises
 */
public static function allSettled(array $promises): Promise;

/**
 * @throws Throwable
 * @param array<int, Async|Promise|callable> $promises
 * @phpstan-param array<int, Async|Promise|callable> $promises
 */
public static function any(array $promises): Promise;

/**
 * @throws Throwable
 * @param array<int, Async|Promise|callable> $promises
 * @phpstan-param array<int, Async|Promise|callable> $promises
 */
public static function race(array $promises): Promise;
Previousawait()Nextc()

Last updated 9 months ago