Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebase Android SDK Tasks API の直列処理について@fireba...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Tatsuya Sawai Tatsuya Sawai
November 21, 2017

Firebase Android SDK Tasks API の直列処理について@firebase.yebisu #1

Avatar for Tatsuya Sawai

Tatsuya Sawai

November 21, 2017
Tweet

More Decks by Tatsuya Sawai

Other Decks in Technology

Transcript

  1. Continuation を使って実装してみると… v a l e x e c u

    t o r : E x e c u t o r = E x e c u t o r s . n e w S i n g l e T h r e a d E x e c u t o r ( ) F i r e b a s e A u t h . g e t I n s t a n c e ( ) . s i g n I n A n o n y m o u s l y ( ) . c o n t i n u e W i t h T a s k ( e x e c u t o r , C o n t i n u a t i o n < A u t h R e s u l t , T a s k < G e t T o k e n R e s u l t > > { i f ( i t . i s S u c c e s s f u l ) { i t . r e s u l t . u s e r . g e t I d T o k e n ( f a l s e ) } e l s e { t h r o w i t . e x c e p t i o n ! ! } } ) / / L i s t e n e r に続く. . . 7
  2. Why Executor? Task はそれぞれ自身で Executor を管理している。Continuation も実態は、 実行したい Task の結果を受け取る

    Task なので、 Executor を用意する必要がある。 Task を自分で用意する際に Executor を指定しないと、 その Task は必ず Main application thread で実行される!!! 9
  3. ライブラリつくりました NeoTask https://goo.gl/KKS5Vh 特徴 100% Kotlin の 軽量 Extension ライブラリ。

    Tasks API を使う際に考えなければならない細かいあれこれを吸収 してくれる。 10
  4. NeoTask を使うと... F i r e b a s e

    A u t h . g e t I n s t a n c e ( ) . s i g n I n A n o n y m o u s l y ( ) . t h e n { i t . u s e r . g e t I d T o k e n ( f a l s e ) } / / L i s t e n e r に続く 簡潔になった! 11