Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Term::Twiddle on Win32 or how to use spinner

by BrowserUk (Patriarch)
on Feb 15, 2003 at 06:14 UTC ( [id://235510]=note: print w/replies, xml ) Need Help??


in reply to Term::Twiddle on Win32 or how to use spinner

Here's a roll-your-own asynchronous spinner using fork under Win32. It's pretty crude as-is, but could be fairly easily wrapped up in a nicer interface.

Update: Added a 100ms sleep (select) to stop the spinner using half the CPU.

#! perl -sw use strict; use Win32::Mutex; $|++; my $name = 'Spin_control'; if ( my $pid = fork() ) { my $n=0; my $mutex =Win32::Mutex->new(0,$name) or die $^E; while($mutex->wait() != -1) { $mutex->release(); print chr(13) . 'Busy'; print substr( '-\|/', $n++ % 4,1) . chr(8); select(undef,undef,undef,0.1); ## Added. } } elsif ( $pid == 0 ) { my $mutex = Win32::Mutex->open($name); $mutex->wait(); print 'Not busy' . chr(13) for 1..1000; print $/; $mutex->release(); my $count; $count++ for 1..1_000_000; $mutex->wait(); print 'Counted to ', $count; } else { warn 'fork() failed'; }

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://235510]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found