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
  1. Promise

then() & catch() & finally()

/**
 * 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;

The then() method will help you create that promise callback when it has been fulfilled.

The catch() method will generate a callback for that promise when it is rejected.

finally() is the method used to set that callback when it's complete.

Example:

$promise = new Promise(function($resolve, $reject) {
    $resolve("Hello World");
});

$promise->then(fn($result) => var_dump($result))
->catch(fn($error) => var_dump($error))
->finnally(fn() => var_dump("PROMISE DONE!"));
Previousresolve() & reject()NextuseCallbacks()

Last updated 1 year ago