Internal helper to execute a fetch request and return a promise
| 52 | |
| 53 | // Internal helper to execute a fetch request and return a promise |
| 54 | fl::task::Promise<Response> execute_fetch_request(const fl::string& url, const FetchOptions& request) { |
| 55 | // Create a promise for this request |
| 56 | auto promise = fl::task::Promise<Response>::create(); |
| 57 | |
| 58 | // Register with fetch manager to ensure it's tracked |
| 59 | FetchManager::instance().register_promise(promise); |
| 60 | |
| 61 | // Get the actual URL to use (use request URL if provided, otherwise use parameter URL) |
| 62 | fl::string fetch_url = request.url().empty() ? url : request.url(); |
| 63 | |
| 64 | // Convert our request to the existing WASM fetch system |
| 65 | auto wasm_request = ::fl::WasmFetchRequest(fetch_url); |
| 66 | |
| 67 | // Use lambda that captures the promise directly (shared_ptr is safe to copy) |
| 68 | // Make the lambda mutable so we can call non-const methods on the captured promise |
| 69 | wasm_request.response([promise](const Response& resp) mutable { |
| 70 | // Complete the promise directly - no need for double storage |
| 71 | if (promise.valid()) { |
| 72 | promise.complete_with_value(resp); |
| 73 | } |
| 74 | }); |
| 75 | |
| 76 | return promise; |
| 77 | } |
| 78 | |
| 79 | |
| 80 |
no test coverage detected