use strict; use warnings; use Tk; use MCE::Hobo; use MCE::Shared; my $msg = MCE::Shared->scalar("Step One"); my $hobo; my $mw = MainWindow->new(); $mw->protocol( WM_DELETE_WINDOW => \&quit ); $mw->geometry("+150+100"); $mw->Label( -text => "Tk + MCE::Hobo Demo", -height => 2, -width => 22 )->pack; my $btn1 = $mw->Button( -text => "Start", -command => \&fun, -width => 10 ); $btn1->pack; my $btn2 = $mw->Button( -text => "Quit", -command => \&quit, -width => 10 ); $btn2->pack; my $timer = $mw->repeat( 100, sub { return unless $hobo; my $text = $msg->get; $btn1->configure( -text => $text ); if ( $hobo->is_joinable ) { $hobo->join; if ( my $err = $hobo->error ) { print {*STDERR} "something went wrong: $err\n"; } $btn1->configure( -state => "normal" ); $hobo = undef; } }); MainLoop(); sub fun { # important, disable button and reset the shared variable $btn1->configure( -state => "disabled" ); $msg->set("Step One"); $hobo = MCE::Hobo->create( sub { sleep 1; $msg->set("Step Two"); sleep 1; $msg->set("Step Three"); }); return; } sub quit { $timer->cancel; $hobo->exit->join if $hobo; exit; }