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
1
540
fetchのCancel Abort方法標準化の変遷 / A History of Cancel Abort Method Standard
・Cancelable Promise
・AbortController
・Browserの対応状況
・Node.jsの対応状況
tipo159
March 29, 2018
Tweet
Share
More Decks by tipo159
See All by tipo159
Type-safe front-end development using Rust/Rustを使った型安全なフロントエンド開発
tipo159
0
480
ReasonReactとReactのAPIの違い / The Difference between ReasonReact API and React API
tipo159
2
550
REASONの紹介 / Introductory talk about REASON
tipo159
1
410
PWAで何ができるようになるのか / What does PWA do
tipo159
1
990
HNPWAの紹介 / Introductory talk about HNPWA
tipo159
2
660
ES2015 Proxyを使ってみた / Introductory talk about ES2015 Proxy
tipo159
1
670
Webコンポーネント関連の最新動向 / Recent Topics on Web Components
tipo159
0
630
SlackはどうやってBrowserViewに乗り換えたのか / How Slack move from webview to BrowserView
tipo159
2
4.4k
コンポーネント再利用ってどこまでするの? / How to reuse components
tipo159
0
930
Other Decks in Programming
See All in Programming
CSC307 Lecture 15
javiergs
PRO
0
220
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
110
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
0
320
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
1k
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
310
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
200
CSC307 Lecture 12
javiergs
PRO
0
460
文字コードの話
qnighy
43
17k
AIに仕事を丸投げしたら、本当に楽になれるのか
dip_tech
PRO
0
180
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
470
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
160
オブザーバビリティ駆動開発って実際どうなの?
yohfee
3
690
Featured
See All Featured
Marketing to machines
jonoalderson
1
5k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
130
Music & Morning Musume
bryan
47
7.1k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
96
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
63
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How to train your dragon (web standard)
notwaldorf
97
6.5k
Building AI with AI
inesmontani
PRO
1
760
The Curious Case for Waylosing
cassininazir
0
260
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
230
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