byancode / promise
Promise Async
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:php
This package is auto-updated.
Last update: 2024-12-28 08:50:33 UTC
README
Installation
You can install the package via composer:
composer require byancode/promise
Usage
use Byancode\RequestCurl; use Byancode\Promise; new Promise(function ($promise) { if (true) { echo 'hola mundo'; $promise->resolve([ 'success' => true ]); echo 'esto no se imprime'; } else { echo 'se produjo un error'; $promise->reject('es un error'); echo 'esto no se imprime'; } })->then(function ($data) { print_r($data) })->catch(function ($message) { echo $message; });
Request promise
Promise::create(function ($promise) { RequestCurl::http()->get( 'http://google.com/', )->then(function($content) use ($promise) { $content = str_replace('div', 'my-div'); $promise->resolve($content); })->catch(function() use ($promise) { $promise->reject('se produjo un error'); }); })->then(function ($data) { print_r($data) })->catch(function ($message) { echo $message; })->run();
Request and trace promise
RequestCurl::trace(function(){ new Promise(function ($promise) { RequestCurl::http()->get( 'http://google.com/', )->then(function($content) use ($promise) { $promise->wrap(function($promise) use ($content) { $content = str_replace('div', 'my-div'); $promise->resolve($content); }); })->catch(function() use ($promise) { $promise->wrap(function($promise) { $promise->reject('se produjo un error'); }); }); })->then(function ($data) { print_r($data) })->catch(function ($message) { echo $message; }); new Promise(function ($promise) { RequestCurl::http()->get( 'http://youtube.com/', )->then(function($content) use ($promise) { $promise->wrap(function($promise) use ($content) { $content = str_replace('div', 'my-div'); $promise->resolve($content); }): })->catch(function() use ($promise) { $promise->wrap(function($promise) { $promise->reject('se produjo un error'); }); }); })->then(function ($data) { print_r($data) })->catch(function ($message) { echo $message; }); });