pods::SDL::Time(3pm)

πŸŽ€ NAME πŸŽ€

SDL::Time β€” An SDL Perl extension for managing timers. This is the pods::SDL::Time(3pm) page, bestie, and we're about to make timers make sense ✨

πŸ¦‹ CATEGORY πŸ¦‹

Core. That's the category, no cap 🫢

✨ SYNOPSIS ✨

Okay so here's the whole vibe in code, exactly as written β€” no edits, no "fixing," just straight copy-paste energy:

        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);

πŸ’… METHODS πŸ’…

Lowkey the main character section. Let's go πŸŽ€

⏰ add_timer ⏰

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

Note the signature literally says SDL::Timer::add_timer β€” keep that exactly as is, iykyk πŸ‘€

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. Periodt.

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.

⚠️ Real talk: 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. That's the one exception, bestie πŸ’–

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.

🧹 remove_timer 🧹

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

Again, the signature says SDL::Timer::remove_timer β€” exact copy, no touchy πŸ™ˆ

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. Slay.

πŸ‘‘ AUTHORS πŸ‘‘

See "AUTHORS" in SDL. That's it, that's the whole authors section 🫢


🌈 That's a wrap, bestie! This page is pods::SDL::Time(3pm) from perl v5.42.3, dated 2026-08-19 β€” mwah πŸ’‹
πŸ“¦ where this page comes from