Skip to content

Timeout idea. #4

@diaspar

Description

@diaspar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions