SDL_WaitAsyncIOResult(3)

πŸ’– SDL_WaitAsyncIOResult πŸ’–

okay bestie, welcome to the SDL_WaitAsyncIOResult(3) page β€” this one lives in the SDL3 FUNCTIONS section of the manual and it's literally the "girl just go to sleep until the work is done" function πŸ›Œβœ¨


✨ NAME ✨

SDL_WaitAsyncIOResult β€” block until an async I/O task queue has a completed task. no cap, that's the whole job πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_asyncio.h>

bool SDL_WaitAsyncIOResult(SDL_AsyncIOQueue *queue, SDL_AsyncIOOutcome *outcome, Sint32 timeoutMS);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: this function puts the calling thread to sleep 😴 until there's a task assigned to the queue that has finished. that's it, that's the function.

if a task assigned to the queue has finished, it returns true and fills in outcome with the details of the task. if no task in the queue has finished, this function returns false. simple as πŸ“

if a task has completed, this function will free its resources and the task pointer will no longer be valid. the task will be removed from the queue. so like, don't go touching that pointer after, bestie, it's gone πŸ‘»

it is safe for multiple threads to call this function on the same queue at once; a completed task will only go to one of the threads. teamwork, but make it mutually exclusive 🫢

⚠️ note that by the nature of various platforms, more than one waiting thread may wake to handle a single task, but only one will obtain it β€” so timeoutMS is a maximum wait time, and this function may return false sooner. it's giving "false alarm, go back to bed" 😭

this function may return false if there was a system error, the OS inadvertently awoke multiple threads, or if SDL_SignalAsyncIOQueue() was called to wake up all waiting threads without a finished task. so false doesn't always mean timeout, iykyk πŸ’€

a timeout can be used to specify a maximum wait time, but rather than polling, it is possible to have a timeout of -1 to wait forever, and use SDL_SignalAsyncIOQueue() to wake up the waiting threads later. obsessed with that pattern fr fr 🌈


🌸 FUNCTION PARAMETERS 🌸

  • queue β€” the async I/O task queue to wait on. the one we're stanning 🎯
  • outcome β€” details of a finished task will be written here. May not be NULL. not me stressing this, it's literally in the docs πŸ™ˆ
  • timeoutMS β€” the maximum time to wait, in milliseconds, or -1 to wait indefinitely. the "how long am I willing to be patient" number ⏳

πŸ‘‘ RETURN VALUE πŸ‘‘

returns true if task has completed, false otherwise. binary. iconic. periodt πŸ’…


⭐ THREAD SAFETY ⭐

it is safe to call this function from any thread. every thread is the main character here, we don't gatekeep 🌟


πŸ’œ AVAILABILITY πŸ’œ

this function is available since SDL 3.2.0. so if you're on something older... bestie, update 😭


πŸ”₯ SEE ALSO πŸ”₯


and that's the page, my love πŸ’– written for Simple Directmedia Layer, SDL 3.4.18 edition β€” go forth, wait on your queues responsibly, and remember: -1 means forever, and forever is a long time πŸŒ™βœ¨

πŸ“¦ where this page comes from