mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-18 01:48:10 +00:00
async: add pure async http client
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
const std = @import("std");
|
||||
const http = std.http;
|
||||
const StdClient = @import("Client.zig");
|
||||
// const hasync = @import("http.zig");
|
||||
const AsyncClient = @import("http.zig").Client;
|
||||
const AsyncRequest = @import("http.zig").Request;
|
||||
|
||||
pub const Loop = @import("jsruntime").Loop;
|
||||
|
||||
@@ -58,3 +59,24 @@ test "blocking mode open/send/wait API" {
|
||||
|
||||
try std.testing.expect(req.response.status == .ok);
|
||||
}
|
||||
|
||||
test "non blocking mode API" {
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
var loop = try Loop.init(alloc);
|
||||
defer loop.deinit();
|
||||
|
||||
var client = AsyncClient.init(alloc, &loop);
|
||||
defer client.deinit();
|
||||
|
||||
var reqs: [10]AsyncRequest = undefined;
|
||||
for (0..reqs.len) |i| {
|
||||
reqs[i] = client.create(try std.Uri.parse(url));
|
||||
try reqs[i].fetch();
|
||||
}
|
||||
|
||||
for (0..reqs.len) |i| {
|
||||
try reqs[i].wait();
|
||||
reqs[i].deinit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user