-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XHR #166
XHR #166
Conversation
POC for async http client: https://github.com/krichprollsch/zig-async-http |
b1d743b
to
5342874
Compare
ba9fc7f
to
0faff39
Compare
done: bool = false, | ||
err: ?anyerror = null, | ||
|
||
pub fn deinit(self: *AsyncRequest) void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit stange to have a deinit without an init
return self.impl.yield(self); | ||
} | ||
|
||
fn onerr(self: *AsyncRequest, err: anyerror) void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onErr
?
|
||
pub fn create(self: *AsyncClient, uri: std.Uri) !AsyncRequest { | ||
return .{ | ||
.impl = YieldImpl.init(self.cli.loop), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Yield is a struct with data, we have to store it's instance on the Request. If it was only a container of functions we wouldn't need that.
src/async/test.zig
Outdated
self.cli.deinit(); | ||
} | ||
|
||
pub fn create(self: *AsyncClient, uri: std.Uri) !AsyncRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's not enough self explanatory. createRequest
?
self.err = err; | ||
} | ||
|
||
pub fn onYield(self: *AsyncRequest, err: ?anyerror) void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onYield is blocking right?
var reqs: [10]AsyncClient.AsyncRequest = undefined; | ||
for (0..reqs.len) |i| { | ||
reqs[i] = try client.create(try std.Uri.parse(url)); | ||
reqs[i].fetch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having difficulties to understand how this is non-blocking.
Let's say we have 3 requests (A, B, C).
For me the execution process is the following:
- Create and launch fetch A
- Create and launch fetch B
- Create and launch fetch C
- Process A
- Process B
- Process C
OK process is done after all requests are created and launched, but still as soon as the onYield callback is called each requests is process on a blocking way.
There is no concurrency here, no?
src/async/test.zig
Outdated
|
||
pub const Loop = @import("jsruntime").Loop; | ||
|
||
const TCPClient = @import("tcp.zig").Client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this const is not used in this file.
5642313
to
d508633
Compare
Replace it with a tested sample implementation
relates with #171
depends on lightpanda-io/zig-js-runtime#193
depends on lightpanda-io/zig-js-runtime#199
depends on lightpanda-io/libdom#9
blocked by lightpanda-io/zig-js-runtime#200
blocked by lightpanda-io/zig-js-runtime#204