GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
pods::SDL::Time(3) User Contributed Perl Documentation pods::SDL::Time(3)

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

Core

 use warnings;
 use strict;
 
 use threads;
 use threads::shared;

 use SDL::Time;

 package foo;

 use SDL ':all';

 SDL::init(SDL_INIT_TIMER);

 my $tick :shared = 0;
 sub ticker { $tick++; warn $tick; return 100; }

 package main;

 my $id = SDL::Time::add_timer(100, 'foo::ticker');

 sleep(2);

 SDL::Time::remove_timer($id);

 my $id = SDL::Timer::add_timer( $ms_interval, $callback );

This runs in a separate thread and a cloned Perl thread. "threads" and "threads::shared" must be used to share any variables the timer uses.

The $callback function, specified with a string of the function's name, will be called after the milliseconds of $interval have elapsed. The actual delay may be longer than specified depending on the underlying OS. The callback function is passed the current timer interval as well as the $interval parameter and should return the next timer interval. If the return value from the callback is 0, the timer is cancelled; otherwise, the timer will continue to run.

The timer callback function may run in a different thread to your main program, so it shouldn't call any functions from within itself. You may call SDL::push_event, however.

"SDL::Time::add_timer" returns the identifier value of the generated timer or undef on error.

Note: You must initialize ("SDL::init") the timer subsystem to use this function.

 SDL::Timer::remove_timer( $id );

The other way to cancel a timer is to use "SDL::Time::remove_timer" on the $id of a timer. This ID is the return value of the "SDL::Time::add_timer" function.

"SDL::Time::remove_timer" returns 0 on success or "-1" on error.

See "AUTHORS" in SDL.
2022-06-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.