zig-async - 評価
評価スケール
基本評価 (100点満点)
| 項目 |
配点 |
評価基準 |
| コンパイル |
10点 |
`zig build` でエラーなく完了 |
| HTTPクライアント |
25点 |
並行フェッチが動作 |
| ファイルI/O |
25点 |
並行読み込みが動作 |
| イベントループ |
20点 |
タイマーが正しく動作 |
| テスト |
10点 |
非同期テストをパス |
| コード品質 |
10点 |
エラー処理、可読性 |
ボーナス評価 (最大30点)
| 項目 |
配点 |
| チャンネル |
10点 |
| 非同期ストリーム |
10点 |
| 接続プール |
10点 |
課題の目的
学習目標
- async/await パターン
- イベント駆動設計 - スレッド vs 非同期I/O
- データ競合の回避 - フレーム
- サスペンドとリジューム習得スキル
- ノンブロッキングI/O実装
- イベントループの設計
- 並行性のデバッグ
評価手順
1. 並行性テスト
test "concurrent fetch" {
var client = AsyncClient.init(testing.allocator);
defer client.deinit();
const start = std.time.milliTimestamp();
const results = try client.fetchAll(&.{
"http://localhost:8080/delay/100",
"http://localhost:8080/delay/100",
"http://localhost:8080/delay/100",
});
const elapsed = std.time.milliTimestamp() - start;
// 並行処理なら ~100ms、順次処理なら ~300ms
try testing.expect(elapsed < 200);
try testing.expect(results.len == 3);
}
2. タイムアウトテスト
test "timeout handling" {
var client = AsyncClient.init(testing.allocator);
client.setTimeout(50); // 50ms timeout
const result = client.fetch("http://localhost:8080/delay/1000");
try testing.expectError(error.Timeout, result);
}
3. イベントループテスト
test "event loop timer" {
var loop = EventLoop.init();
var fired = false;
loop.setTimeout(struct {
fn callback() void {
fired = true;
}
}.callback, 10);
loop.run();
try testing.expect(fired);
}
減点対象
| 項目 |
減点 |
| データ競合 |
-25点 |
| デッドロック |
-20点 |
| リソースリーク |
-15点 |
| タイムアウト未処理 |
-10点 |
合格基準
マンダトリーパート: 80点以上
並行処理による性能向上が確認できること