diff --git a/README.md b/README.md index 39ad3a2..31a8cb6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # AWS Lambda Runtime for Zig - + [](/LICENSE) Write _AWS Lambda_ functions in the Zig programming language to achieve blazing fast invocations and cold starts! @@ -422,4 +422,4 @@ by the use of this software, part of it, or its derivatives. See [LICENSE](/LICE for the complete terms of use. **_AWS Lambda Runtime for Zig_ is not an official _Amazon Web Services_ software, -nor is it affiliated with _Amazon Web Services, Inc_.** \ No newline at end of file +nor is it affiliated with _Amazon Web Services, Inc_.** diff --git a/build.zig.zon b/build.zig.zon index 3fcf39a..47f8695 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,7 +3,7 @@ .version = "0.4.0", .fingerprint = 0xdc70f8287a69c300, - .minimum_zig_version = "0.15.0", + .minimum_zig_version = "0.16.0-dev.2821+3edaef9e0", .dependencies = .{}, diff --git a/demo/debug.zig b/demo/debug.zig index eeda369..b55e44c 100644 --- a/demo/debug.zig +++ b/demo/debug.zig @@ -9,7 +9,7 @@ pub fn main() void { } fn handler(ctx: lambda.Context, event: []const u8) ![]const u8 { - var str: std.io.Writer.Allocating = try .initCapacity(ctx.arena, 1024); + var str: std.Io.Writer.Allocating = try .initCapacity(ctx.arena, 1024); const cfg = ctx.config; try str.writer.print( diff --git a/demo/stream.zig b/demo/stream.zig index 1b33c2a..3c39c7c 100644 --- a/demo/stream.zig +++ b/demo/stream.zig @@ -9,7 +9,7 @@ pub fn main() void { } /// 0.5 seconds (in nanoseconds) -const HALF_SEC = 0.5 * std.time.ns_per_s; +const HALF_SEC = std.time.ns_per_s / 2; fn handler(_: lambda.Context, _: []const u8, stream: lambda.Stream) !void { // Start a textual event stream with a prelude body. @@ -17,7 +17,7 @@ fn handler(_: lambda.Context, _: []const u8, stream: lambda.Stream) !void { const writer = try stream.openPrint("text/event-stream", "Loading {d} messages...\n\n", .{3}); // Wait for half a second. - std.Thread.sleep(HALF_SEC); + try sleepHalfSecond(); // Append multiple to the stream’s buffer without publishing to the client. try writer.writeAll("id: 0\n"); @@ -25,11 +25,11 @@ fn handler(_: lambda.Context, _: []const u8, stream: lambda.Stream) !void { // Send the buffered response to the client. try stream.publish(); - std.Thread.sleep(HALF_SEC); + try sleepHalfSecond(); try writer.writeAll("id: 1\ndata: This is message number 2\n\n"); try stream.publish(); - std.Thread.sleep(HALF_SEC); + try sleepHalfSecond(); // One last message to the client... try writer.print("id: {d}\ndata: This is message number {d}\n\n", .{ 2, 3 }); @@ -46,3 +46,10 @@ fn handler(_: lambda.Context, _: []const u8, stream: lambda.Stream) !void { fn doSomeCleanup() void { // Some cleanup work... } + +fn sleepHalfSecond() !void { + try std.Io.Clock.Duration.sleep(.{ + .clock = .awake, + .raw = .fromNanoseconds(HALF_SEC), + }, std.Options.debug_io); +} diff --git a/demo/url_buffer.zig b/demo/url_buffer.zig index e338fc8..de41980 100644 --- a/demo/url_buffer.zig +++ b/demo/url_buffer.zig @@ -90,7 +90,7 @@ fn homePage(ctx: lambda.Context) ![]const u8 { /// The `url.Request` contains both the HTTP request and additional AWS metadata. fn ipAddrPage(ctx: lambda.Context, req: lambda.url.Request) ![]const u8 { // Generate dynamic HTML content, note the usage of an arena allocator. - var html: std.io.Writer.Allocating = .init(ctx.arena); + var html: std.Io.Writer.Allocating = .init(ctx.arena); try html.writer.writeAll(global_nav); if (req.request_context.http.source_ip) |addr| { @@ -110,7 +110,7 @@ fn ipAddrPage(ctx: lambda.Context, req: lambda.url.Request) ![]const u8 { /// Use a parsed query parameter provided by the decoded request to greet the user. fn greetPage(ctx: lambda.Context, req: lambda.url.Request) ![]const u8 { - var html: std.io.Writer.Allocating = .init(ctx.arena); + var html: std.Io.Writer.Allocating = .init(ctx.arena); try html.writer.writeAll(global_nav); @@ -165,7 +165,7 @@ fn storagePage(ctx: lambda.Context, req: lambda.url.Request) ![]const u8 { } // Encode the cookie value - var new_cookie: std.io.Writer.Allocating = .init(ctx.arena); + var new_cookie: std.Io.Writer.Allocating = .init(ctx.arena); errdefer new_cookie.deinit(); try new_cookie.writer.writeAll("store="); try std.base64.standard.Encoder.encodeWriter(&new_cookie.writer, value); @@ -176,7 +176,7 @@ fn storagePage(ctx: lambda.Context, req: lambda.url.Request) ![]const u8 { } // Render a form to display and update the stored value. - var html: std.io.Writer.Allocating = .init(ctx.arena); + var html: std.Io.Writer.Allocating = .init(ctx.arena); try html.writer.writeAll(global_nav); try html.writer.print( \\