Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout idea. #4

Closed
diaspar opened this issue Sep 22, 2014 · 1 comment
Closed

Timeout idea. #4

diaspar opened this issue Sep 22, 2014 · 1 comment

Comments

@diaspar
Copy link

diaspar commented Sep 22, 2014

This is more a question than an issue. Do you think an optional parameter for timeout will be beneficial?

If found this code in a legacy project I am mantaining

    /**
     * Keep trying a number of times until it actually saves. This is for really important tasks.
     *
     * @param $entity
     * @param int $iterations
     * @return bool
     */
    public function reallySave( $entity, $iterations = 5 ) {
        for( $i = 0; $i < $iterations; $i++ ) {
            if( $entity->save() ) {
                return TRUE;
            }

            //sleep for 100 milliseconds between each try. Without the delay two back to back attempts are likely to fail.
            usleep( 100 * 1000 );
        }
        return FALSE;
    }

I don't know if this is a bad practice, but I think retry could replace this.

@igorw
Copy link
Owner

igorw commented Sep 22, 2014

Duplicate of #2.

@igorw igorw closed this as completed Sep 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants