libfetch 0.0.0
A lightweight asynchronous HTTP/1.1 client library implementing a subset of the WHATWG Fetch API.
Loading...
Searching...
No Matches
Event Loop Management

Control the event loop for asynchronous operations. More...

Functions

bool fetch_event_loop_start (void)
 Start the event loop.
 
void fetch_event_loop_stop (void)
 Stop the event loop.
 
int fetch_event_loop_process (uint32_t timeout_ms)
 Process events in the event loop (NON-BLOCKING with timeout)
 
bool fetch_event_loop_is_running (void)
 Check if the event loop is running.
 

Detailed Description

Control the event loop for asynchronous operations.

Function Documentation

◆ fetch_event_loop_is_running()

bool fetch_event_loop_is_running ( void )

Check if the event loop is running.

Returns
true if event loop is active

◆ fetch_event_loop_process()

int fetch_event_loop_process ( uint32_t timeout_ms)

Process events in the event loop (NON-BLOCKING with timeout)

Call this regularly to make progress on asynchronous requests. This function will return after processing available events or when the timeout expires.

Parameters
timeout_msMaximum time to wait for events (0 for non-blocking)
Returns
Number of events processed, or -1 if event loop not running
Note
This function may block up to timeout_ms milliseconds
Call this regularly (e.g., in your main loop) to drive async requests
// Main application loop
while (application_running) {
// Process fetch events (non-blocking)
int events = fetch_event_loop_process(0);
if (events < 0) {
printf("Event loop stopped unexpectedly\n");
break;
}
// Handle application events
handle_ui_events();
handle_other_work();
// Small delay to prevent busy waiting
usleep(1000); // 1ms
}
// Alternative: blocking approach with timeout
while (has_pending_requests) {
int events = fetch_event_loop_process(100); // Wait up to 100ms
if (events < 0) break; // Event loop stopped
// Check if requests completed
check_promise_states();
}
int fetch_event_loop_process(uint32_t timeout_ms)
Process events in the event loop (NON-BLOCKING with timeout)
Definition fetch.c:7339

◆ fetch_event_loop_start()

bool fetch_event_loop_start ( void )

Start the event loop.

Must be called before making asynchronous requests. The event loop runs in the calling thread and must be driven by calling fetch_event_loop_process() regularly.

Returns
true if event loop started successfully
Note
Threading: Event loop runs in the calling thread
Memory: No cleanup required for starting, but call fetch_event_loop_stop() to clean up
fprintf(stderr, "Failed to start event loop\n");
return -1;
}
// Event loop is now ready for async requests
// You must call fetch_event_loop_process() to drive it
bool fetch_event_loop_start(void)
Start the event loop.
Definition fetch.c:7407

◆ fetch_event_loop_stop()

void fetch_event_loop_stop ( void )

Stop the event loop.

Cancels all pending requests and shuts down the event loop. Call this during cleanup to free event loop resources.

Note
Memory: Frees all event loop resources and cancels pending requests