The calls are documented in POD at the end of Async::Tiny. Just run "perldoc Async/Tiny.pm" to see the formatted version.

The first argument to addRepeatCallback is the interval in seconds, and the second is the callback subref. Any extra arguments are provided to the callback sub when it is called.

In this case they are the row number at which to display the count, and an array ref which holds as its first element the actual count. This array ref holds the "state" for this particular "thread" of repeated callbacks, so I can have two (or more, if desired) independent counts running at the "same" time using the same counter sub.

( see the "counter" sub for how those two extra arguments are handled.)

"simultaneously" ? yes and no :)
My example program shows two counters incrementing "simultaneously" at two different rates.

Here's another example program (a newer version of the "bars.pl" in the POD) where each row sweeps at its own rate independent of the other rows (and "simultaneously").

(This is one of my test programs for the timerqueue.)

#!/usr/bin/perl # # bars.pl - multiple independent timers using Async::Tiny Ppoll use Curses; use Term::ReadKey; use Async::Tiny; use strict; use warnings; my ($width, $height) = GetTerminalSize; my @lines = ( '-' x $width ) x $height; my $endcode; my $t = Async::Tiny->new; $t->addDelayCallback( 100, sub { $endcode = 'endrepeat' } ); for my $row (0 .. $#lines) { $t->addRepeatCallback( (3 + rand 20) / 50 , sub { s/-/#/ or s/#*\K#/=/ or tr/=/-/ for $lines[$row]; addstr $row, 0, $lines[$row]; refresh; $endcode; } ); } initscr; curs_set 0; addstr 0, 0, '-' x $width x $height; $t->eventloop; endwin;

I'll see if I can do a simple game with action, interaction, and score keeping as "proof of concept" sometime soon.


In reply to Re^4: Weird Output with Threads and NCurses by Anonymous Monk
in thread Weird Output with Threads and NCurses by var121

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.