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
fetchのCancel Abort方法標準化の変遷 / A History of Cance...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
tipo159
March 29, 2018
Programming
570
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
fetchのCancel Abort方法標準化の変遷 / A History of Cancel Abort Method Standard
・Cancelable Promise
・AbortController
・Browserの対応状況
・Node.jsの対応状況
tipo159
March 29, 2018
More Decks by tipo159
See All by tipo159
Type-safe front-end development using Rust/Rustを使った型安全なフロントエンド開発
tipo159
0
520
ReasonReactとReactのAPIの違い / The Difference between ReasonReact API and React API
tipo159
2
610
REASONの紹介 / Introductory talk about REASON
tipo159
1
440
PWAで何ができるようになるのか / What does PWA do
tipo159
1
1k
HNPWAの紹介 / Introductory talk about HNPWA
tipo159
2
690
ES2015 Proxyを使ってみた / Introductory talk about ES2015 Proxy
tipo159
1
690
Webコンポーネント関連の最新動向 / Recent Topics on Web Components
tipo159
0
670
SlackはどうやってBrowserViewに乗り換えたのか / How Slack move from webview to BrowserView
tipo159
2
4.5k
コンポーネント再利用ってどこまでするの? / How to reuse components
tipo159
0
950
Other Decks in Programming
See All in Programming
VibeCodingからAgenticWorkflowへ
starfish719
0
870
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
490
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
3
2k
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
180
バグを直したら useEffect が消えた
colorful12
3
700
Oxlintはいいぞ(続)
yug1224
1
460
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
550
初めての模倣学習とVLA
natsutan
0
250
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
2
210
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
720
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
240
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
Between Models and Reality
mayunak
4
410
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.4k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
440
The agentic SEO stack - context over prompts
schlessera
0
880
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
660
Code Reviewing Like a Champion
maltzj
528
40k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
940
Transcript
fetchͷCancel/Abortํ๏ඪ४Խͷมભ Meguro.es #14 2018.3.29 tipo159
ΞδΣϯμ • Cancelable Promise (2015.4.10 - 2016.12.16) • AbortController (2017.1.5
- ) • BrowserͷରԠঢ়گ • Node.jsͷରԠঢ়گ 2
Cancelable Promise (2015.4.10 - 2016.12.16) • JavaScriptͷPromise༷ͷՃ • ओͳ༰ •
cancelΛresolve, rejectͱҧ͏ୈ3ͷঢ়ଶͱͯ͠Ճ • .NETͰΘΕ͍ͯͨCancel TokenΛͬͯΩϟϯηϧ • Domenic Denicola(Googleࣾһ)͕ɼ2016.12.16ʹGoogle ෦ͷରͷͨΊऔΓԼ͛(ৄࡉෆ໌) https://github.com/tc39/proposal-cancelable-promises 3
Cancelable Promiseͷαϯϓϧ async function f(cancelToken) { await a(); cancelToken.cancelIfRequested(); await
b(); } const ct = new CancelToken(cancel => { cancelButton.onclick = cancel; }); f(ct); // NOTE: will be canceled if they click the cancel button 4
AbortController (2017.1.5 - ) • ࠷ॳPromise༷ͷՃΛࢦ͍͕ͯͨ͠ɼDOM༷ ʹՃ͞Εͨ • ओͳ༰ •
AbortControllerΦϒδΣΫτΛͬͯΞϘʔτ • PromiseͷػೳՃͳ͠ • fetchҎ֎ʹద༻Մೳ • WHATWGͷDOM༷ʹՃࡁΈ https://dom.spec.whatwg.org/ 5
AbortControllerͷྫ var controller = new AbortController(); var signal = controller.signal;
var downloadBtn = document.querySelector('.download'); var abortBtn = document.querySelector('.abort'); downloadBtn.addEventListener('click', fetchVideo); abortBtn.addEventListener('click', function() { controller.abort(); console.log('Download aborted'); }); function fetchVideo() { ... fetch(url, {signal}).then(function(response) { ... }).catch(function(e) { reports.textContent = 'Download error: ' + e.message; }) } 6
BrowserͷରԠঢ়گ • αϙʔτࡁΈ • Chrome 66 • Edge 16 •
Firefox 57 • ະαϙʔτ • Safari (Technology Preview 42 2017.10.18ʙ ਖ਼ࣜαϙʔτະ) 7
Node.jsͷରԠঢ়گ • Node.jsʹDOMؔ࿈API͕ͳ͍ͨΊ༻ෆՄ • polyfillΛ͑༻Մೳ https://www.npmjs.com/package/abortcontroller-polyfill 8