Enviar pesquisa
Carregar
Async – react, don't wait
•
4 gostaram
•
3,314 visualizações
Johan Andrén
Seguir
Slides from my topconf 2013 talk
Leia menos
Leia mais
Tecnologia
Negócios
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 36
Baixar agora
Baixar para ler offline
Recomendados
Async - react, don't wait - PingConf
Async - react, don't wait - PingConf
Johan Andrén
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Konrad Malawski
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
krivachy
Streaming all the things with akka streams
Streaming all the things with akka streams
Johan Andrén
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
Dominik Gruber
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Reactivesummit
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
Johan Andrén
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
Konstantin Tsykulenko
Recomendados
Async - react, don't wait - PingConf
Async - react, don't wait - PingConf
Johan Andrén
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Konrad Malawski
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
krivachy
Streaming all the things with akka streams
Streaming all the things with akka streams
Johan Andrén
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
Dominik Gruber
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Reactivesummit
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
Johan Andrén
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
Konstantin Tsykulenko
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
Konrad Malawski
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Konrad Malawski
Reactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
Johan Andrén
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
Gioia Ballin
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
Riccardo Terrell
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"
Konrad Malawski
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
Johan Andrén
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroup
Johan Andrén
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
Konrad Malawski
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
Manuel Bernhardt
Buiilding reactive distributed systems with Akka
Buiilding reactive distributed systems with Akka
Johan Andrén
Concurrecny inf sharp
Concurrecny inf sharp
Riccardo Terrell
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
Johan Andrén
DDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
Konrad Malawski
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
Konrad Malawski
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
Manuel Bernhardt
Reactive Summit 2017 Highlights!
Reactive Summit 2017 Highlights!
Fabio Tiriticco
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
emptysquare
Mais conteúdo relacionado
Mais procurados
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
Konrad Malawski
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Konrad Malawski
Reactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
Johan Andrén
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
Gioia Ballin
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
Riccardo Terrell
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"
Konrad Malawski
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
Johan Andrén
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Konrad Malawski
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroup
Johan Andrén
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
Konrad Malawski
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
Konrad Malawski
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
Manuel Bernhardt
Buiilding reactive distributed systems with Akka
Buiilding reactive distributed systems with Akka
Johan Andrén
Concurrecny inf sharp
Concurrecny inf sharp
Riccardo Terrell
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
Johan Andrén
DDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
Konrad Malawski
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
Konrad Malawski
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
Manuel Bernhardt
Reactive Summit 2017 Highlights!
Reactive Summit 2017 Highlights!
Fabio Tiriticco
Mais procurados
(20)
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Reactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroup
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
Buiilding reactive distributed systems with Akka
Buiilding reactive distributed systems with Akka
Concurrecny inf sharp
Concurrecny inf sharp
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
DDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
Reactive Summit 2017 Highlights!
Reactive Summit 2017 Highlights!
Semelhante a Async – react, don't wait
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
Leonardo Borges
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
emptysquare
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
SmartLogic
Intro to ReactJS
Intro to ReactJS
Harvard Web Working Group
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
Andrey Breslav
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
Scott Keck-Warren
4 mishchevskii - testing stage18-
4 mishchevskii - testing stage18-
Ievgenii Katsan
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
Ilya Grigorik
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Greg Vaughn
Rethink Async with RXJS
Rethink Async with RXJS
devObjective
Rethink Async With RXJS
Rethink Async With RXJS
Ryan Anklam
Rethink Async with RXJS
Rethink Async with RXJS
ColdFusionConference
From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017
Agustin Ramos
Beyond Page Level Metrics
Beyond Page Level Metrics
Philip Tellis
Streaming Dataflow with Apache Flink
Streaming Dataflow with Apache Flink
huguk
The History of React-Hot-Loader
The History of React-Hot-Loader
Anton Korzunov
Intro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
Graham Weldon
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
tarcieri
Testing sync engine
Testing sync engine
Ilya Puchka
Semelhante a Async – react, don't wait
(20)
Functional Reactive Programming / Compositional Event Systems
Functional Reactive Programming / Compositional Event Systems
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
Intro to ReactJS
Intro to ReactJS
JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
Static Code Analysis PHP[tek] 2023
Static Code Analysis PHP[tek] 2023
4 mishchevskii - testing stage18-
4 mishchevskii - testing stage18-
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Elixir Elevated: The Ups and Downs of OTP at ElixirConf2014
Rethink Async with RXJS
Rethink Async with RXJS
Rethink Async With RXJS
Rethink Async With RXJS
Rethink Async with RXJS
Rethink Async with RXJS
From Elixir to Akka (and back) - ElixirConf Mx 2017
From Elixir to Akka (and back) - ElixirConf Mx 2017
Beyond Page Level Metrics
Beyond Page Level Metrics
Streaming Dataflow with Apache Flink
Streaming Dataflow with Apache Flink
The History of React-Hot-Loader
The History of React-Hot-Loader
Intro to Asynchronous Javascript
Intro to Asynchronous Javascript
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
Concurrent programming with Celluloid (MWRC 2012)
Concurrent programming with Celluloid (MWRC 2012)
Testing sync engine
Testing sync engine
Mais de Johan Andrén
Next generation message driven systems with Akka
Next generation message driven systems with Akka
Johan Andrén
Next generation actors with Akka
Next generation actors with Akka
Johan Andrén
Next generation message driven systems with Akka
Next generation message driven systems with Akka
Johan Andrén
Networks and types - the future of Akka
Networks and types - the future of Akka
Johan Andrén
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streams
Johan Andrén
VJUG24 - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
Johan Andrén
Introduction to akka actors with java 8
Introduction to akka actors with java 8
Johan Andrén
Scala frukostseminarium
Scala frukostseminarium
Johan Andrén
Introduction to Akka
Introduction to Akka
Johan Andrén
Akka frukostseminarium
Akka frukostseminarium
Johan Andrén
Macros and reflection in scala 2.10
Macros and reflection in scala 2.10
Johan Andrén
Introduction to Scala
Introduction to Scala
Johan Andrén
Duchess scala-2012
Duchess scala-2012
Johan Andrén
Mais de Johan Andrén
(13)
Next generation message driven systems with Akka
Next generation message driven systems with Akka
Next generation actors with Akka
Next generation actors with Akka
Next generation message driven systems with Akka
Next generation message driven systems with Akka
Networks and types - the future of Akka
Networks and types - the future of Akka
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streams
VJUG24 - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
Introduction to akka actors with java 8
Introduction to akka actors with java 8
Scala frukostseminarium
Scala frukostseminarium
Introduction to Akka
Introduction to Akka
Akka frukostseminarium
Akka frukostseminarium
Macros and reflection in scala 2.10
Macros and reflection in scala 2.10
Introduction to Scala
Introduction to Scala
Duchess scala-2012
Duchess scala-2012
Último
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Andrey Devyatkin
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
wesley chun
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
lior mazor
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
sammart93
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Principled Technologies
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Roshan Dwivedi
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
apidays
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
MIND CTI
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Khushali Kathiriya
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
Último
(20)
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Async – react, don't wait
1.
Async React instead of waiting
for better times Johan Andrén johan.andren@mejsla.se @apnylle
2.
In the olden
days... ... there was a way to write web applications that bound 1 thread per request oh, wait! let me fix that for me
3.
Most modern web frameworks do
bind 1 thread per request
4.
do bind 1
thread per request t1 Request Thread pool t1 ReSponse
5.
What does that
thread spend most of its time doing? Hint:
6.
Wait Request YOur logic Blocked yOur logic ReSponse WS
7.
Why is this
a problem? • threadpool depletion • server choked with 5% cpu usage • unrelated requests affected
8.
Async! nodejs All kinds of Cool
Shit you never heard about
9.
WUT!? Let someone invoke
our logic when a resource is available What is a resource? • network • disk • internal state
10.
Don´t call us We´ll
call you Our logic WS Async HTTP-client Our logic
11.
What do we
need? • callback based clients/drivers/libs • framework support but doesn’t this lead to...
12.
”Callback Hell”? 1 GMaps.geocode({! 2 address:
fromAddress,! 3 callback: function( results, status ) {! 4 if ( status == "OK" ) {! 5 fromLatLng = results[0].geometry.location;! 6 GMaps.geocode({! 7 address: toAddress,! 8 callback: function( results, status ) {! 9 if ( status == "OK" ) {! 10 toLatLng = results[0].geometry.location;! 11 map.getRoutes({! 12 origin: [ fromLatLng.lat(), fromLatLng.lng() ],! 13 destination: [ toLatLng.lat(), toLatLng.lng() ],! 14 travelMode: "driving",! 15 unitSystem: "imperial",! 16 callback: function( e ){! 17 console.log("ANNNND FINALLY here's the directions.. 18 // do something with e! 19 }! 20 });! 21 }! 22 }! 23 });! 24 }!
13.
25 }! 26 }); Not with
better abstractions! • futures / promises • actors
14.
Future[T] Empty Completed ( Failed ) t
15.
Composition Future[A] Future[B] Map When A arrives Apply
this A B transformation
16.
Play action 1 package
controllers! 2 ! 3 import play.api.mvc._! 4 ! 5 object LuckyNumberController extends Controller {! 6 ! 7 def giveMeLuckyNumber = Action {! 8 ! 9 Ok(views.html.luckyNumber(42))! 10! 11 }! 12 ! 13 }
17.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action {! ! val fResponse: Future[Response] = ! WS.url("http://lucky-number.api/lucky-number").get! ! ! ! ! ! ! ! ! }! ! } Will start execute here
18.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action {! ! val fResponse: Future[Response] = ! WS.url("http://lucky-number.api/lucky-number").get! ! ! ! ! ! ! ! ! }! ! } THe future response
19.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action {! ! val fResponse: Future[Response] = WS.url("http://lucky-number.api/lucky-number").get! ! val fNumber: Future[Int] = fResponse.map { response: Response =>! Integer.parseInt(response.body)! }! ! ! ! ! }! ! } When it arrives: do this Response Int Transformation
20.
Future[T] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action {! ! val fResponse: Future[Response] = WS.url("http://lucky-number.api/lucky-number").get! ! val fNumber: Future[Int] = fResponse.map { response: Response =>! Integer.parseInt(response.body)! }! ! ! ! ! }! ! } (On this Execution context)
21.
Future[T] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action {! ! val fResponse: Future[Response] = WS.url("http://lucky-number.api/lucky-number").get! ! val fNumber: Future[Int] = fResponse.map { response: Response =>! Integer.parseInt(response.body)! }! ! fNumber.map { number =>! Ok(views.html.luckyNumber(number))! }! }! ! } When it arrives: do this Transformation
22.
Future[T] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package controllers! ! import scala.concurrent.Future! import
play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action.async {! ! val fResponse: Future[Response] = WS.url("http://lucky-number.api/lucky-number").get! ! val fNumber: Future[Int] = fResponse.map { response: Response =>! Integer.parseInt(response.body)! }! ! fNumber.map { number =>! Ok(views.html.luckyNumber(number))! }! }! ! } Play allows us to return a Future[Result]
23.
If there was
an exception 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Future[T] package controllers! ! import scala.concurrent.Future! import play.api.libs.ws._! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action.async {! ! val fResponse: Future[Response] = WS.url("http://lucky-number.api/lucky-number").get! ! val fNumber: Future[Int] = fResponse.map { response: Response =>! Integer.parseInt(response.body)! }! ! fNumber.map { number =>! Ok(views.html.luckyNumber(number))! }! }! ! }
24.
Future[T] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package controllers! ! import play.api.libs.ws._! import
play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! object LuckyNumberController extends Controller {! ! def giveMeLuckyNumber = Action.async {! for {! response <- WS.url("http://lucky-number.api/lucky-number").get! } yield {! val number = Integer.parseInt(response.body)! Ok(views.html.luckyNumber(number))! }! }! ! }
25.
Actors State Inbox Behaviour
26.
• no work
- no thread • react - no waiting • can have private state
27.
Actor 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package controllers! ! import akka.actor.Actor! ! case
object GiveMeNumber! case class HereYaGo(number: Int)! ! class LuckyNumberGenerator extends Actor {! ! var nextNumber = 42! ! def receive = {! case GiveMeNumber =>! sender ! HereYaGo(nextNumber)! nextNumber += 1! ! }! }
28.
Actor 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package controllers! ! import akka.actor.Actor! ! case
object GiveMeNumber! case class HereYaGo(number: Int)! ! class LuckyNumberGenerator extends Actor {! ! var nextNumber = 42! ! def receive = {! case GiveMeNumber =>! sender ! HereYaGo(nextNumber)! nextNumber += 1! ! }! } state (mutable)
29.
Actor 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package controllers! ! import akka.actor.Actor! ! case
object GiveMeNumber! case class HereYaGo(number: Int)! ! class LuckyNumberGenerator extends Actor {! ! var nextNumber = 42! ! def receive = {! case GiveMeNumber =>! sender ! HereYaGo(nextNumber)! nextNumber += 1! ! }! } for each message
30.
Controller (calling actor) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package
controllers! ! import akka.actor._! import akka.pattern.ask! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! class LuckyNumberController(numberGenerator: ActorRef) extends Controller {! ! def giveMeLuckyNumber = Action.async {! for {! response <- (numberGenerator ? GiveMeNumber).mapTo[HereYaGo]! } yield {! Ok(views.html.luckyNumber(response.number))! }! }! ! } Di (someone gave it to us)
31.
Controller (calling actor) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package
controllers! ! import akka.actor._! import akka.pattern.ask! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! class LuckyNumberController(numberGenerator: ActorRef) extends Controller {! ! def giveMeLuckyNumber = Action.async {! for {! response <- (numberGenerator ? GiveMeNumber).mapTo[HereYaGo]! } yield {! Ok(views.html.luckyNumber(response.number))! }! }! ! } Sends message, gives us Future[Any] (reply)
32.
Controller (calling actor) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package
controllers! ! import akka.actor._! import akka.pattern.ask! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! class LuckyNumberController(numberGenerator: ActorRef) extends Controller {! ! def giveMeLuckyNumber = Action.async {! for {! response <- (numberGenerator ? GiveMeNumber).mapTo[HereYaGo]! } yield {! Ok(views.html.luckyNumber(response.number))! }! }! ! } We know what we will get back
33.
Controller (calling actor) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package
controllers! ! import akka.actor._! import akka.pattern.ask! import play.api.libs.concurrent.Execution.Implicits.defaultContext! import play.api.mvc._! ! class LuckyNumberController(numberGenerator: ActorRef) extends Controller {! ! def giveMeLuckyNumber = Action.async {! for {! response <- (numberGenerator ? GiveMeNumber).mapTo[HereYaGo]! } yield {! Ok(views.html.luckyNumber(response.number))! }! }! ! } Make a webpage out of that
34.
What to look
out for • really heavy computations • blocking by miss-take • jdbc :(
35.
I wanna try
it! www.playframework.com typesafe.com
36.
Qs? K Thx Bye! Johan
Andrén johan.andren@mejsla.se @apnylle
Baixar agora