Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
javascriptの非同期処理・過去と未来
Search
Taketoshi Aono(青野健利 a.k.a brn)
June 07, 2017
Programming
0
140
javascriptの非同期処理・過去と未来
javascriptの非同期処理の振り返りと、未来の実装についての紹介
Taketoshi Aono(青野健利 a.k.a brn)
June 07, 2017
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
6
3k
Parsing Javascript
brn
13
9.1k
JSON & Object Tips
brn
1
440
CA 1Day Youth Bootcamp for Frontend LT
brn
0
870
Modern TypeScript
brn
2
770
javascript - behind the scene
brn
3
710
tc39 proposals
brn
0
830
プロダクト開発とTypeScript
brn
8
2.9k
React-Springでリッチなアニメーション
brn
1
650
Other Decks in Programming
See All in Programming
DROBEの生成AI活用事例 with AWS
ippey
0
140
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.5k
PHPカンファレンス名古屋2025 タスク分解の試行錯誤〜レビュー負荷を下げるために〜
soichi
1
640
Datadog DBMでなにができる? JDDUG Meetup#7
nealle
0
120
CloudNativePGを布教したい
nnaka2992
0
100
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
240
昭和の職場からアジャイルの世界へ
kumagoro95
1
410
Formの複雑さに立ち向かう
bmthd
1
900
Go 1.24でジェネリックになった型エイリアスの紹介
syumai
2
260
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
0
110
Jakarta EE meets AI
ivargrimstad
0
110
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
140
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
40
2.5k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Being A Developer After 40
akosma
89
590k
Designing Experiences People Love
moore
140
23k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Writing Fast Ruby
sferik
628
61k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
GraphQLとの向き合い方2022年版
quramy
44
13k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
For a Future-Friendly Web
brad_frost
176
9.6k
Embracing the Ebb and Flow
colly
84
4.6k
Optimizing for Happiness
mojombo
376
70k
Transcript
Past and Future of Asynchronous Javascript
せ: @brn (ꫬꅿ⨳ⵃ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger ـؚٗ:
http://abcdef.gets.b6n.ch/
What is Asynchronous? javascriptחֶֽꬊず劍Ⳣ椚הכծךةأָؙ植㖈ךjavascriptךstack ♳ח㶷㖈ׇ׆ծ㼛勻ךוַֿך儗挿דⱄןstack♳ח䗁䌓ׅⳢ椚ד֮կ
What is Asynchronous? e e. .g g. . s se
et tT Ti im me eo ou ut t setTimeoutꟼ侧כ植㖈ך؝٦ٕأةحؙ♳דㄎן⳿ׁהծ䭷㹀ׁ 儗דأ؛آُ٦ٕ涫ꐮ׃Ⳣ椚穄✪ָׅծ䭷㹀ׁ儗ָ穗麓ׅ הծ植㖈ךⳢ椚ךⴖ湡ח؝٦ٕغحؙꟼ侧ָㄎן⳿ׁկ
Callback ֿך״ֲזꬊず劍ةأؙⳢ椚ׅךחծjavascriptדכꟼ侧ؔـآؙؑز 䒷侧ח床ׅ؝٦ٕغحؙ䕎䒭⢪גְկ someAsyncJob(function() {…}); ֿכꟼ侧㘗鎉铂דכ竰竲床׃הㄎלךדׅկ
jQuery.Deferred jQueryדכֿךꬊず劍Ⳣ椚Deferredהְֲ倯岀דֲתֻⳢ椚׃ג ְת׃կ function delayHello() { var d = new
$.Deferred; setTimeout(function(){ d.resolve('Hello'); }, 1000); return d.promise(); } delayHello().done(function(word) {console.log(word)})
Promise/A+ ַאגծNodejsהWebךjs垥彊⻉׃״ֲה׃ծCommonJSהְֲ穈籼 ָ倜זꬊず劍Ⳣ椚堣圓㹀纏ׅկ ך➿邌涸ז㹋鄲ד֮Qך؝٦س Q.fcall(promisedStep1) .then(promisedStep2) .then(promisedStep3) .then(promisedStep4) .then(function (value4)
{ // Do something with value4 }) .catch(function (error) { // Handle any error from all above steps }) .done();
Promise ׃גծאְחEcmascriptחPromiseָ㼪Ⰵׁ const p = new Promise((resolve, reject) => {
setTimeout(() => resolve('hello')); }); p.then(word => console.log(word));
Problems ծPromiseָ؝٦ٕغحؙך㉏겗挿ׅץג鍑寸׃הכ鎉ְꨇְկ 穠㽷䕎㢌ִ؝٦ٕغحؙ䕎䒭ד׃ַזְךדծ؝٦سָ醱꧟חזהծ ּׅ鋅בֻזկ const p = new Promise(resolve =>
{ setTimeout(() => resolve('hello')); }) p.then(word => { setTimeout(() => resolve(`${word} world`)); }) .then(word => console.log(word));
Generator & co ׁחծGeneratorEcmascriptח㼪Ⰵׁկ Generator⽃⡤דכꬊず劍Ⳣ椚ך㉏겗כ鍑寸דֹזְָծcoػح؛٦آ ⢪ֲה⟃♴ך圫חזկ const hello = ()
=> new Promise(resolve => { setTimeout(() => resolve("hello"), 300); }); const world = () => new Promise(resolve => { setTimeout(() => resolve("world"), 300); }); co(function* () { var hello = yield hello(); var world = yield world(); return `${hello} ${world}`; }).then(word => console.log(value));
async & await ׃גծֿ驎תִծasync awaitהְֲ堣圓ָES7חג䱰欽ׁկ ֿכPromiseⷚ涸ח何㊣׃ծקר䩛竲ֹ倯ך膷דꬊず劍Ⳣ椚鎸鶢ד ֹկ async helloWorld() {
const hello = await new Promise(resolve => { setTimeout(() => resolve('hello')); }); const word = await new Promise(resolve => { setTimeout(() => resolve('world')); }); console.log(`${hello} ${world}`) }
Asynchronous Iterators ׃ծasync awaitג׃גꬊず劍ٕ٦فכ㺁僒דכזְկ ֿדծAsynchronous Iteratorsהְֲ➬圫ָ䲿周⚥דծ植㖈Stage3 ח֮կ async function* readLines(path)
{ let file = await fileOpen(path); try { while (!file.EOF) { yield await file.readLine(); } } finally { await file.close(); } } for await (const line of readLines(filePath)) { console.log(line); }
➙וֲׅץַֹ 植㖈ך؝٦س؝٦ٕغحؙ䕎䒭ד剅ְגְ㜥さծכּׅװ״ֲկ ꬊ䌢ח؝٦سأ؛٦ׇׁٕךָꨇ׃ֻז׃ծغؚך庛䎮חזկ • Babel٥typescriptⵃ欽׃גְזasync٥await⢪ְת׃׳ֲկ • 稆ךJSזBluebird㼪Ⰵׅկ • 㢩鿇ךٓ؎ـָٓٔ⢪ִזְז知僒Promise㹋鄲ׅկ https://gist.github.com/brn/4f639a5bdb845f0aebe8e0725691a442