natiny_resource_load_async

C
void natiny_resource_load_async(
    const char* path,
    natiny_resource_async_cb callback,
    void* userdata
);

Asynchronously loads a resource. The callback fires when loading completes.

Parameters

Name Type Description
path const char* Path to the resource file
callback natiny_resource_async_cb Called when loading completes
userdata void* User pointer passed to the callback

Callback

The callback receives: - success - 1 on success, 0 on failure. - data - pointer to loaded bytes (valid only during callback). - data_len - number of loaded bytes. - userdata - forwarded user pointer.

Example

C
void on_loaded(int success, const uint8_t* data, uint32_t data_len, void* ud) {
    if (!success || !data || data_len == 0) {
        return;
    }
    NatinyResource res = natiny_resource_from_data(data, data_len);
    /* use res */
    natiny_resource_destroy(res);
}

void start_load(void) {
    natiny_resource_load_async("data/big.bin", on_loaded, NULL);
}

Notes

  • Completed callbacks are dispatched automatically by natiny_backend_loop before the frame callback runs.
  • Ideal for large assets that should not block the main thread.