dispatch_after(3)

πŸ“¦ version 0~svn197, in ubuntu jammy

πŸ’– dispatch_after(3) β€” the "do this later bestie" page πŸ’–

okay so this is the manual for dispatch_after, from section 3 (library functions) of the Darwin manual. she's a libc / dispatch girlie and she is iconic ✨


🌸 NAME 🌸

dispatch_after β€” schedule blocks for deferred execution πŸ•

like… run this thing, but NOT right now. later. on purpose. πŸ’…


✨ SYNOPSIS ✨

#include <dispatch/dispatch.h>

void
dispatch_after(dispatch_time_t when, dispatch_queue_t queue,
    void (^block)(void));

void
dispatch_after_f(dispatch_time_t when, dispatch_queue_t queue,
    void *context, void (*function)(void *));

two whole functions bestie, both yours 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so dispatch_after() submits the block to the given queue at the time specified by the when parameter. that's it, that's the whole vibe. ⏰

the when parameter is a value created by dispatch_time() or dispatch_walltime(). you don't just make one up, okay, you get it from those two. no cap.

if you want a more detailed description about submitting blocks to queues, go see dispatch_async(3). she's the main character of that topic, this page is just her time-delayed cousin πŸŽ€


⚠️ CAVEATS ⚠️

listen up bestie, this part matters πŸ’€
  • Specifying DISPATCH_TIME_NOW as the when parameter is supported, but it is not as efficient as calling dispatch_async(). it works!! it's just lowkey doing the most for no reason πŸ™ˆ
  • The result of passing DISPATCH_TIME_FOREVER as the when parameter is undefined. not "it waits forever", not "it never runs" β€” undefined. do not pass go. do not collect $200. 🚫

🧚 FUNDAMENTALS 🧚

the dispatch_after() function is a wrapper around dispatch_after_f(). that's the lore. one is the cute front, the other is the machinery underneath. iykyk πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

go read those too, they're all part of the same friend group fr fr πŸ’œ


mwah πŸ’‹ this page is from the Darwin manual, dated May 1, 2009. love that for her. stay scheduled, stay slay βœ¨πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from