Skip to Content
プログラミングTypeScript ―スケールするJavaScriptアプリケーション開発
book

プログラミングTypeScript ―スケールするJavaScriptアプリケーション開発

by Boris Cherny, 今村 謙士, 原 隆文
March 2020
Intermediate to advanced
376 pages
5h 9m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミングTypeScript ―スケールするJavaScriptアプリケーション開発

8章非同期プログラミングと並行、並列処理

ここまで本書では、主に同期プログラム(synchronous program)——何らかの入力を取り、何らかの処理を行い、完了に至るまで一本道で実行されるプログラム——を扱ってきました。しかし、本当に興味深いプログラム——ネットワーク要求を行ったり、データベースやファイルシステムの入出力を扱ったり、ユーザーとの対話に応答したり、CPU負荷の高い作業を別々のスレッドに振り分けたり、といった現実世界のアプリケーションの基礎的要素——はすべて、コールバック、プロミス、ストリームなどの非同期API(asynchronous API)を利用しています。

これらの非同期タスクは、JavaScriptが真に輝きを放つ分野で、JavaやC++のような主流のマルチスレッド言語から、それ自身を際立たせているものです。V8やSpiderMonkeyのようなポピュラーなJavaScriptエンジンは、他のタスクがアイドル状態にある間、1つのスレッド上にタスクを賢く多重化させることで、従来、多くのスレッドを必要としていた処理を1つのスレッドで行います。このイベントループ(event loop)は、JavaScriptエンジンにとって標準的なスレッドモデルであり、おそらく読者も使用しているはずです。エンドユーザーの観点からすると、エンジンがイベントループのモデルを使用しているのか、それともマルチスレッドのモデルを使用しているのかは、通常は重要ではありません。しかしこれから説明するところの、さまざまなものがどのように機能するのか、さまざまなものをどのように設計すべきか、という議論には影響を及ぼします。

このイベントループの並行(concurrency)モデルは、マルチスレッドプログラミングに固有のよくある問題や、同期されるデータ型、ミューテックス、セマフォなど、マルチスレッドに関するあらゆるものによるオーバーヘッドをJavaScriptが回避するための方法です。また、複数のスレッドにまたがってJavaScriptを実行する場合、共有メモリーはめったに使われません。よくあるパターンは、メッセージパッシング(メッセージの受け渡し)を使い、スレッド間でデータを送信するときにそれをシリアライズすることです。これは、Erlang、アクターシステム、その他の純粋な関数型の並行モデルを想起させる設計であり、JavaScriptでのマルチスレッドプログラミングを誰でも扱えるようにするものです。 ...

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

リーダーの作法 ―ささいなことをていねいに

リーダーの作法 ―ささいなことをていねいに

Michael Lopp, 和智 右桂
行動を変えるデザイン ―心理学と行動経済学をプロダクトデザインに活用する

行動を変えるデザイン ―心理学と行動経済学をプロダクトデザインに活用する

Stephen Wendel, 武山 政直, 相島 雅樹, 反中 望, 松村 草也

Publisher Resources

ISBN: 9784873119045Other