Skip to Content
Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理
book

Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

by Maxwell Flitton, Caroline Morton, 中田 秀基
July 2025
Intermediate to advanced
284 pages
4h 4m
Japanese
O'Reilly Japan, Inc.
Content preview from Async Rust ―高いパフォーマンスと安全性を両立するRustによる非同期処理

5章コルーチン

本書をここまで読めば非同期プログラミングに馴染んできただろう。await文を見たら、フューチャ、タスク、スレッド、キューが舞台裏で動作していることがわかるようになったはずだ。しかし、非同期プログラミングの構成要素はどうだろう。非同期ランタイムを用いずにコードを停止し再開できたらどうだろう。さらに、この停止・再開機構を用いて、通常のテストフレームワークでコードをテストできないだろうか。このテストでは、多様なポーリングの順序と設定のもとでのコードの挙動をテストできる。また、この停止・再開機構は同期コードと非同期コードのインタフェースとしても機能する。ここで登場するのがコルーチンだ。

本章を読めば、コルーチンを定義し、その使用法を説明できるようになるはずだ。コルーチンをプログラムに統合し、大量にメモリを消費する可能性のあるタスクでも、メモリ消費量を抑えることができるようになる。さらに非同期の機能を非同期ランタイムを用いずに、コルーチンと基本的なエグゼキュータを用いて模擬できるようになる。つまり、非同期ランタイムを用いずに、プログラムのメインスレッドで非同期機能を利用できるようになる。さらに、コルーチンがポーリングされるタイミングと順序を細粒度に制御できるようになる。

[注記]

本書では、執筆時点のRustのnightlyビルドのコルーチン構文を用いる。この構文は変更される可能性があるし、安定化されるかもしれない。構文の変更は面倒だが、本章で述べるコルーチンの基礎は変わらない。構文が変わっても、コルーチン全体の実装や使用法に変わりはない。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Async Rust

Async Rust

Maxwell Flitton, Caroline Morton
Rust Web Programming

Rust Web Programming

Maxwell Flitton

Publisher Resources

ISBN: 9784814401185Publisher Website