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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners