Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AsyncStorageをNodeのREPLから操作するためにTop-levelでawaitし...
Search
joe_re
July 14, 2017
Technology
550
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AsyncStorageをNodeのREPLから操作するためにTop-levelでawaitしたい人生だった
五反田.js #8 LT資料
joe_re
July 14, 2017
More Decks by joe_re
See All by joe_re
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
3
370
AI時代のGraphQL
joere
3
440
Eyes on Claude Code
joere
0
170
Building Public API with GraphQL
joere
3
160
Traversing the GraphQL AST and Calculating Query Costs
joere
0
1.4k
Real-Time applications with GraphQL
joere
0
330
Prisma2 with Graphql
joere
3
1.1k
Go beyound static on Netlify
joere
1
410
Building Real-time Vue App
joere
4
4.8k
Other Decks in Technology
See All in Technology
reInvent2026stby LT00 "Change your life!"
shinichirokawano
1
560
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
550
AIエージェントの監視、思考を見るか行動を見るか / Monitoring AI Agents: Thoughts or Actions
yusukeshimizu
1
100
(swiftc) NonCopyableとライフタイム修飾子
teamhimeh
0
170
AI AgentによるEmbedded SREの取り組み
tgidgd
1
340
Building Audio Plugin Ecosystem for Android in 2026
atsushieno
2
140
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
590
続・ソフトウェアアーキテクトのための意思決定術: Decision Readiness, Revisited — When AI Changes the Economics of Software Architecture
snoozer05
PRO
4
1.2k
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
1
7.2k
現場を動かすAIエージェント#2_製造業現場でのAI活用から見た、ハマる罠と実践知
kintotechdev
1
130
Software Engineering in an AI-Driven World
erikjhordan_rey
0
110
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
300
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
Paper Plane
katiecoart
PRO
5
54k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
600
Building Flexible Design Systems
yeseniaperezcruz
330
41k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Practical Orchestrator
shlominoach
192
12k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
290
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
470
Claude Code のすすめ
schroneko
67
230k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
340
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Transcript
AsyncStorage をNode の REPL から操作するために Toplevel でawait したい 人生だった @joe_re
Who am I? twitter: @joe_re github: @joere working in freee.K.K
What is AsyncStorage? ReactNative の標準で搭載されたkeyvalue ストレージ 気軽にReactNative に永続化したいデータを持つときに便利 ReactNative で使えるLocalStorage
みたいなもの
Example Persisting date: try { await AsyncStorage.setItem('@MySuperStore:key', 'I like to
save it.'); } catch (error) { // Error saving data } Fetching date: try { const value = await AsyncStorage.getItem('@MySuperStore:key'); if (value !== null){ // We have data!! console.log(value); } } catch (error) { // Error retrieving data }
AsyncStorage をNode のREPL から操作したいという欲望 AsyncStorage には外部から叩けるAPI は用意されていない 開発中にデータ構造が変わったときにアプリケーションに データを修正するためのコードを書くのは面倒 ちゃんとデータが保存されたかどうか確かめるのも面倒
REPL からAsyncStorage のAPI を叩きたい (rails console みたいなイメージ)
作った https://github.com/joere/asyncstoragerepl
DEMO
仕組み Node とReactNative との通信はWebsocket で行う REPL 起動時に子プロセスとしてReactNative アプリケーションと通信するWSS を立ち上げる REPL
とWSS はプロセス間通信を行う
イメージ図
ん?
どうしてこうなった
Node.js ではTop Level で非同期処理の 結果を扱えない 人類はES2017 よりasync/await を獲得したが、 await はasync
function の中でしか使えない // ng function request { const response = await fetch( '/data.json' ); const json = await response.json(); const result = await hydrateSomehow(json); return result; } // ok function async request { const response = await fetch( '/data.json' ); const json = await response.json(); const result = await hydrateSomehow(json); return result; }
REPL で Promise オブジェクトを 扱おうとすると.. > let out = null;
> promiseObj.then((res) => { out = res }); > out // finally available here
だるすぎワロた
Toplevel await is a footgun https://gist.github.com/Rich Harris/0b6f317657f5167663b493c722647221 Toplevel のawait を許すと1
つの依存を解決するだけでも、 その先の関係のない処理まで止めざるを得ない await は直列を強要するので、ネットワークを介した処理の 並列化ができない
Example(borrow from Harris) // main.js import './foo.js'; import './bar.js'; //
foo.js await delay( Math.random() * 1000 ); console.log( 'foo happened' ); // bar.js await delay( Math.random() * 1000 ); console.log( 'bar happened' );
将来的にはToplevel await が できるかも? https://github.com/tc39/ecmascriptasyncawait/issues/9
それはそれとしてNode のREPL に 例外的に入る可能性も https://github.com/nodejs/node/issues/13209
今回はこのような実装に _resolveMessageFromRN(fileName) { let json = {}; let received =
false; for (let i = 0; i < this.timeout; i++) { sleep.msleep(100); const fileContent = fs.readFileSync(fileName, 'utf8'); if (fileContent) { json = JSON.parse(fileContent); delete this.que[Number(json.queId)]; received = true; break; } sleep.msleep(900); } fs.unlinkSync(fileName); if (!received) { throw new Error("can't receive response from ReactNative Application"); } if (json.error === 1) { throw new Error(json.message); } return json.result; }
そうは言っても結構便利です。 ReactNative のお供にぜひ!
ありがとうございました