1SDL::Time(3)          User Contributed Perl Documentation         SDL::Time(3)
2
3
4

NAME

6       SDL::Time - An SDL Perl extension for managing timers
7

CATEGORY

9       Core
10

SYNOPSIS

12        use warnings;
13        use strict;
14
15        use threads;
16        use threads::shared;
17
18        use SDL::Time;
19
20        package foo;
21
22        use SDL ':all';
23
24        SDL::init(SDL_INIT_TIMER);
25
26        my $tick :shared = 0;
27        sub ticker { $tick++; warn $tick; return 100; }
28
29        package main;
30
31        my $id = SDL::Time::add_timer(100, 'foo::ticker');
32
33        sleep(2);
34
35        SDL::Time::remove_timer($id);
36

METHODS

38   add_timer
39        my $id = SDL::Timer::add_timer( $ms_interval, $callback );
40
41       This runs in a separate thread and a cloned Perl thread.  "threads" and
42       "threads::shared" must be used to share any variables the timer uses.
43
44       The $callback function, specified with a string of the function's name,
45       will be called after the milliseconds of $interval have elapsed.  The
46       actual delay may be longer than specified depending on the underlying
47       OS.  The callback function is passed the current timer interval as well
48       as the $interval parameter and should return the next timer interval.
49       If the return value from the callback is 0, the timer is cancelled;
50       otherwise, the timer will continue to run.
51
52       The timer callback function may run in a different thread to your main
53       program, so it shouldn't call any functions from within itself.  You
54       may call SDL::push_event, however.
55
56       "SDL::Time::add_timer" returns the identifier value of the generated
57       timer or undef on error.
58
59       Note: You must initialize ("SDL::init") the timer subsystem to use this
60       function.
61
62   remove_timer
63        SDL::Timer::remove_timer( $id );
64
65       The other way to cancel a timer is to use "SDL::Time::remove_timer" on
66       the $id of a timer.  This ID is the return value of the
67       "SDL::Time::add_timer" function.
68
69       "SDL::Time::remove_timer" returns 0 on success or "-1" on error.
70

AUTHORS

72       See "AUTHORS" in SDL.
73
74
75
76perl v5.30.0                      2019-07-26                      SDL::Time(3)
Impressum