Skip to content

MZAWeb/Retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Retry

https://www.youtube.com/watch?v=dQw4w9WgXcQ

Small helper to call a given callable multiple times if the first time it fails. Allows you to define what a fail means, how many retries, and how much time between retries.

Note that this is not async. The execution will be stopped here until all retries finish or the execution is succesful.

Sample usage:

$response = Retry::calling( 'wp_remote_post' )
                 ->with_args( array( $url, $args ) )
                 ->times( 3 )
                 ->with_delay( 1 )
                 ->failed_if( 'is_wp_error' )
                 ->go();

The callables can be closures for more advanced behaviour:

$response = Retry::calling( 'wp_remote_post' )
                 ->with_args( array( $url, $args ) )
                 ->times( 3 )
                 ->failed_if( function ( $response ) {
	                 if ( $response->response['code'] === 404 ) {
		                 return false;
	                 }

	                 return true;
                 } )
                 ->go();

About

Don't give up just now!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages