{ ## main loop my $cache = 'current'; # Hope for the best if (not cache_is_good()) { $cache = 'stale'; # Changed expectations if (i_am_the_writer()) { if (cache_is_stale()) { unless (start_background_update()) { $cache = 'current'; # Gotta do it foreground } } else { $cache = 'current'; # Have nothing to show, gotta do it } } elsif(not cache_is_stale()) { # Stuck, gotta retry close_cache(); sleep 5; redo; } update_cache() if $cache eq 'current'; # Make it so } show_cache($cache); } sub start_background_update { # NOTE: Uses implicit returns. if (i_can_fork()) { unless (i_am_the_parent()) { be_a_child(); update_cache(); exit 0; } } }