Stopwatch

NAME

Timer::Stopwatch - Schedule and reset repeated time measurements

SYNOPSIS


use Timer::Stopwatch;

my $irregular-supply = Supply.interval(1).grep: { Bool.pick }

my $timer = Timer::Stopwatch.new;
react {
    whenever $irregular-supply {
        note "{ now.DateTime.hh-mm-ss }: Received an irregular event";

        # Wait up to 2 seconds for the next event
        $timer.reset: 2;
    }
    whenever $timer {
        note "It's been { .round } seconds since the last event";
        $timer.stop;
    }
    whenever Promise.in: 20 {
        note 'Stopping after 20 seconds';
        $timer.stop;
    }
    whenever $timer.Promise {
        note "Timer was stopped. We're done";
        done;
    }
}

# OUTPUT:
# 20:33:39: Received an irregular event
# 20:33:40: Received an irregular event
# 20:33:42: Received an irregular event
# It's been 2 seconds since the last event
# Timer was stopped. We're done

DESCRIPTION

Timer::Stopwatch is a resettable, stoppable wrapper around a Supply that can be used to mark multiple moments in time.

METHODS

AUTHOR

José Joaquín Atria <[email protected]>

Copyright 2021 José Joaquín Atria

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Timer::Stopwatch v0.1.0

Schedule and reset repeated time measurements

Authors

  • José Joaquín Atria

License

Artistic-2.0

Dependencies

OO::MonitorsTimer::Breakable

Test Dependencies

Provides

  • Timer::Stopwatch

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.