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
Software Engineering in an AI-Driven World
erikjhordan_rey
0
110
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
270
2026 Apache Flink Community Checkpoint
rmetzger
0
140
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
300
Autonomous AI Lakehouse - Live AI Hubから始めるセキュアなAIデータ活用 -
oracle4engineer
PRO
3
190
SLOを阻む不安
sraku2159
0
220
AI Search (Foundry IQ) におけるRAGデータの準備と配置
ryomaru0825
1
140
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
400
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
590
IoTとは〜? 数字で見るSORACOM UG【SORACOM UG Explorer 2026】
soracom
PRO
0
170
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
780
自律的なチームを作るためにTechPMがやらないこと
ny7760
0
500
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
699
190k
Facilitating Awesome Meetings
lara
57
7.2k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
600
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Building the Perfect Custom Keyboard
takai
2
940
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
エンジニアに許された特別な時間の終わり
watany
109
250k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
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 のお供にぜひ!
ありがとうございました