Source: www.amitmerchant.com

Using JavaScript-style Promises in PHP

Category: PHP, javascript

A blog on PHP, JavaScript and more Amit Merchant · July 23, 2020 · ⋆ PHP So, in a nutshell (in the context of JavaScript), A promise is an object that may produce a single value sometime in the future: a resolved value, or a reason that it’s not resolved (e.g., a network error occurred) Based on this, a promise can be in one of these 3 possible states: A Promise in JavaScript can be created like so.

Just like JavaScript, we have a Promise object which accepts two callbacks: a $resolver and $canceller (just like JavaScript promises) like so.

Oh, and you can also chain the promises if you want to perform additional operations on the promise result like so.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners