https://meguroes.connpass.com/event/93734 で話しました。
©2018 Wantedly, Inc.Actor Model in ReasonMeguro.es #1602.Aug.2018 - Yuki Yamada
View Slide
©2018 Wantedly, Inc.Self Introduction
©2018 Wantedly, Inc.Yuki Yamada@yamadayukiI’m an Engineer @ WantedlyI write JS, Golang, Ruby, Swift … etc.Now I focus on Frontend Engineering atFeed squad.Self Introduction
©2018 Wantedly, Inc.Actor Model
©2018 Wantedly, Inc.Actor ModelActor ModelΞΫλʔͱ͍͏ঢ়ଶΛอͪॲཧΛ͢ΔΦϒδΣΫτͦΕͧΕ͕ Mailbox ͱ͍͏ΩϡʔͱΞυϨεΛ͍࣋ͬͯΔΞΫλʔୡͦΕͧΕࣗͷॲཧΛߦ͍ͭͭඞཁ͕͋ΕଞͷΞΫλʔʹϝοηʔδΛૹͬͯॲཧΛ͓ئ͍͢ΔͦΕͧΕͷॲཧඇಉظͰ࣮ߦ͞ΕΔͨΊɺฒߦॲཧͷͨΊͷϩοΫಉظ͕ෆཁʹͳΔݴޠϨϕϧͰ ErlangϥΠϒϥϦͰ Akka (JVM) ͕දྫ
©2018 Wantedly, Inc.JavaScript ͰͬͯΈ͍ͨ Actor Model
©2018 Wantedly, Inc.Ͱී௨ͷ JavaScript Ͱ͏·͘Ͱ͖Δؾ͕͠ͳ͍ Actor Model
©2018 Wantedly, Inc.1. OCaml• Statically typed, Functional, Pattern Matching2. Erlang• Actor Model, Functional, Pattern Matching3. JavaScript• Fun, Insanely flexibleActor Model
©2018 Wantedly, Inc.ؔܕݴޠͰ Pattern Matching ͷԸܙΛड͚ͭͭ Actor Model Γ͍ͨActor Model
©2018 Wantedly, Inc.Actor ModelRoppongi.js #1 ͰLT͠·ͨ͠BuckleScript ϕʔεͰܕݕࠪͰ͖ΔɺFacebook ۘͷAltJSBuckleScript OCaml ΛίϯύΠϧͯ͠ JavaScript ʹ͢Δͭhttps://speakerdeck.com/yamadayuki/react-with-reason
©2018 Wantedly, Inc.Actor ModelؔܕݴޠͰ Pattern Matching ͷԸܙΛड͚ͭͭ Actor Model Ͱ͖ͦ͏
©2018 Wantedly, Inc.Actor Model in Reason
©2018 Wantedly, Inc.Actor Model in ReasonJS Ͱ Actor Modelncthbrt/nact , ncthbrt/reason-nact“Nact is redux but for the server.”Akka Erlang ͷΞϓϩʔνΛࢀߟʹ Node.js Ͱ ActorModel ͕࣮ݱͰ͖ΔΑ͏ʹ࡞ΒΕͨϥΠϒϥϦDENQUE (https://github.com/Salakar/denque) ͱPromise ϕʔεͰ࣮͞Ε͍ͯΔTimeout Supervision αϙʔτ͞Ε͍ͯΔJavaScript ͔Β Reason/BuckleScript ͔Β͑Δ
©2018 Wantedly, Inc.Actor Model in ReasonGetting StartedѫࡰΛฦͯ͘͠ΕΔΞΫλʔͷੜ“spawnStateless” ͱ͍͏ؔͰΞΫλʔ͕ੜͰ͖ΔΞΫλʔʹରͯ͠ “dispatch” ͱ͍͏ؔͰϝοηʔδΛૹΔ͜ͱͰɺॲཧΛ࣮ߦͤ͞Δ͜ͱ͕Ͱ͖Δ
©2018 Wantedly, Inc.Actor Model in ReasonspawnStateless“Stateless” ͱ suffix ͕͍͍ͭͯΔ͚ͩ͋ͬͯɺ͜ͷؔͰ State Λ࣋ͬͨΞΫλʔΛੜͰ͖ͳ͍ͦͷͨΊɺ࣮ߦͯ͠΄͍͠ॲཧ͚ͩΛͤΔ͜ͱ͔͠Ͱ͖ͳ͍ɻ࣮ߦͨ݁͠ՌͩͬͨΓΛ࣍ʹ͍ճ͢ͱ͔Ͱ͖ͳ͍
©2018 Wantedly, Inc.Actor Model in Reasonspawnݟͨ “Stateless” ͷ suffix ͕औΕ͚ͨͩ͜ͷؔͰ State Λ࣋ͬͨΞΫλʔΛੜͰ͖Δӈͷίʔυ counter ͷ࣮amount Λࢦఆͯ͠૿͢ྔΛϝοηʔδͰૹΔͱɺ͍·ͷঢ়ଶͷ amount ʹՃࢉ͞Εͯίϯιʔϧʹग़ྗ͞ΕΔɻ
©2018 Wantedly, Inc.Actor Model in ReasonspawnॲཧΛهड़͢Δؔͷୈ1Ҿʹ State ͕ͬͯ͘ΔͷͰɺͦΕΛར༻ͯ͠ॲཧΛߦ͑Δ12ߦ͜ͷΞΫλʔ͕ॳظԽ͞Εͨ࣌Ͱͷinitial state Λฦ͍ͯ͠ΔͳͷͰ state ʹ {amount: int} ͱ͍͏ํ͕ͬͯ͘Δ
©2018 Wantedly, Inc.Actor Model in ReasonCommunicationΞΫλʔಉ࢜Ͱ௨৴͢Δͱ͖ɺྫ͑ϝοηʔδͷૹΓओ͕ඞཁͳ߹͕͋ΔϝοηʔδΛૹΔͱ͖ʹࣗࣗΛϝοηʔδʹՃ͑Δ͜ͱͰɺϝοηʔδΛड͚औͬͨଆͰૹΓओΛΔ͜ͱ͕Ͱ͖ΔΞΫλʔࣗମ actorRef(msgType) ͷΑ͏ͳܕʹͳΔͷͰɺϝοηʔδͷܕΛఆٛ͢Δ࣌ʹར༻͢Δ
©2018 Wantedly, Inc.Actor Model in ReasonCommunicationpong ͔Β ping ʹϝοηʔδΛૹΔͱ͜Ζ7ߦͰ sender(ping or pong) ʹରͯ͠ctx.self Λϝοηʔδʹ֨ೲͯ͠ૹΔΑ͏ʹͳ͍ͬͯΔctx.self ΞΫλʔࣗʹͳ͍ͬͯͯɺϝοηʔδΛड͚औΔଆͰૹΓओ͕Θ͔Δ“<-<” ͱ͍͏ͷಠࣗʹఆٛ͞ΕͨΦϖϨʔλͰdispatch ͷγϣʔτϋϯυ
©2018 Wantedly, Inc.Actor Model in ReasonSupervision͠ΞΫλʔ͕Ϋϥογϡͨ͠߹ɺඇಉظॲཧͷҰ࿈ͷྲྀΕΛࢭΊͳ͍ͨΊʹ෮׆ͤ͞Δඞཁ͕͋ΔΫϥογϡͨ͠ͱ͖ʹ෮׆Ͱ͖ΔΑ͏ʹsupervisor Λ༻ҙ͢Δ͜ͱͰɺࣗಈతʹΞΫλʔΛ෮׆ͤ͞ΒΕΔ
©2018 Wantedly, Inc.DEMOActor Model in Reason
©2018 Wantedly, Inc.1. νϟοτͷΑ͏ͳΠϕϯτϕʔεͷαʔό2. ඇಉظδϣϒΩϡʔγεςϜActor Model in ReasonActor Model ͷ͍ॴ
©2018 Wantedly, Inc.JSͰϓϩτλΠϐϯάͰ͖ΔʂActor Model in Reason
©2018 Wantedly, Inc.1. Actor Model ΛͬͯඇಉظॲཧΛ͍͍ײ͡ʹ2. nact Reason Ͱهड़Ͱ͖ΔͷͰܕͷԸܙ͕͋Δ3. Reason ָ͍͠Actor Model in Reason·ͱΊ
©2018 Wantedly, Inc.Actor Model in ReasonMeguro.es #1602.Aug.2018 - Yuki YamadaFin.