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

Functions for request cancellation. More...

Functions

fetch_abort_controller_tfetch_abort_controller_new (void)
 Create a new abort controller.
 
void fetch_abort_controller_abort (fetch_abort_controller_t *controller, const char *reason)
 Abort operations using this controller.
 
bool fetch_abort_controller_aborted (const fetch_abort_controller_t *controller)
 Check if controller has been aborted.
 
void fetch_abort_controller_free (fetch_abort_controller_t *controller)
 Free an abort controller.
 

Detailed Description

Functions for request cancellation.

Function Documentation

◆ fetch_abort_controller_abort()

void fetch_abort_controller_abort ( fetch_abort_controller_t * controller,
const char * reason )

Abort operations using this controller.

Parameters
controllerThe abort controller
reasonOptional reason for abortion

◆ fetch_abort_controller_aborted()

bool fetch_abort_controller_aborted ( const fetch_abort_controller_t * controller)

Check if controller has been aborted.

Parameters
controllerThe abort controller
Returns
true if aborted

◆ fetch_abort_controller_free()

void fetch_abort_controller_free ( fetch_abort_controller_t * controller)

Free an abort controller.

Parameters
controllerController to free (can be NULL)
Note
Memory: Frees the controller

◆ fetch_abort_controller_new()

fetch_abort_controller_t * fetch_abort_controller_new ( void )

Create a new abort controller.

Returns
New abort controller (caller owns, must call fetch_abort_controller_free() if not passed to fetch_init), or NULL on failure
Note
Memory: Returns owned object that must be freed
if (!controller) {
fprintf(stderr, "Failed to create abort controller\n");
return -1;
}
fetch_init_signal(init, controller); // Controller is borrowed by init
fetch_promise_t *promise = fetch_async("https://httpbin.org/delay/10", init);
// Cancel after 5 seconds
sleep(5);
fetch_abort_controller_abort(controller, "Took too long");
// Cleanup (order matters)
fetch_init_free(init); // This frees the controller
fetch_abort_controller_t * fetch_abort_controller_new(void)
Create a new abort controller.
Definition fetch.c:8833
void fetch_abort_controller_abort(fetch_abort_controller_t *controller, const char *reason)
Abort operations using this controller.
Definition fetch.c:8839
fetch_promise_t * fetch_async(const char *url, fetch_init_t *init)
Make an asynchronous HTTP request (NON-BLOCKING)
Definition fetch.c:7764
void fetch_init_free(fetch_init_t *init)
Free a request configuration.
Definition fetch.c:8881
fetch_init_t * fetch_init_new(void)
Create a new request configuration.
Definition fetch.c:8861
fetch_init_t * fetch_init_signal(fetch_init_t *init, fetch_abort_controller_t *signal)
Set abort signal (fluent interface)
Definition fetch.c:8919
void fetch_promise_free(fetch_promise_t *promise)
Free a promise object.
Definition fetch.c:8401
Abort controller for cancelling requests.
Definition fetch.h:371
Request configuration options.
Definition fetch.h:482
Promise for asynchronous fetch operations.
Definition fetch.h:563