SlideShare uma empresa Scribd logo
1 de 20
Promise of a better
future
Pooja Akshantal
Rahul Goma Phulore
Who are we?
What we are going to talk about
• How concurrency and parallelism are different
ideas
• Why concurrency is important
• Futures and promises
• DEMO!
• Pitfalls
Concurrency ≠ Parallelism
Concurrency is a program-
structuring technique in which
there are multiple threads of
control
A parallel program is one that
uses a multiplicity of
computational hardware (e.g.
multiple processor cores)
Structure Execution
Dealing with lots of things at
once
Doing lots of things at once
Orthogonality illustrated
Javascript
promises, Python
generators
Java and Scala
futures
Well… lots of
things
Parallel
collections
Fall of Moore’s law
Age of multicore
• Multicore has become a norm!
• Need to exploit parallelism to perform
• Good concurrency abstractions a way to
get there
Futures and promises
Futures and promises
• Can be thought of as a single concurrency
abstraction
Future ≈ Cheap thread
• Futures are multiplexed dynamically onto
threads as needed.
• Managed by ExecutionContext.
• It’s practical to have hundreds of thousands
going at once.
• Spawn away!
Code Time
Async and non-blocking
• Goal: Do not block current thread while
waiting for the result of the future.
• Callbacks:
– Register callback which is invoked asynchronously
when future is completed
– Async computations do not block
Callbacks?!
There is a solution!
• Higher-order functions / combinators
• for-comprehensions
• Other abstractions
Running example
• Collect statistics for a
facebook page
• For every post on the
page:
– Collect all likes
– Collect all comments
• Aggregate results into popularity score
Code Time
Other parallels
• Error recovery combinators
– recover
– recoverWith
• Collection operations
– map: (Seq[A], A ⇒ B) ⇒ Seq[B]
mapF: (Seq[A], A ⇒ Future[B]) ⇒ Future[Seq[B]]
– filter: (Seq[A], A ⇒ Boolean) ⇒ Seq[A]
filterF: (Seq[A], A ⇒ Future[Boolean]) ⇒ Future[Seq[A]]
Pitfalls
• Interactions with thread-unsafe libraries
• ThreadLocal variables
• Retries, time-outs not very natural
• Simpler than other concurrency models in
many ways, but still incur some cognitive cost
Credits
• Heather Miller, for her material on
relationship between futures and promises
• Simon Marlow and Rob Pike, for their
material on concurrency and parallelism
• Josh Suereth, for his Github example
(Inspiration for our facebook example)
• Scala, Play, and Akka teams for all their
amazing work
Thank You!
☺

Mais conteúdo relacionado

Mais procurados

Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 

Mais procurados (20)

Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
Grokking TechTalk #24: Thiết kế hệ thống Background Job Queue bằng Ruby & Pos...
 
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & AirflowBuilding a Data Ingestion & Processing Pipeline with Spark & Airflow
Building a Data Ingestion & Processing Pipeline with Spark & Airflow
 
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink TensorflowFlink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
 
Elk meetup
Elk meetupElk meetup
Elk meetup
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
Building Serverless Machine Learning Models in the Cloud [PyData DC]
Building Serverless Machine Learning Models in the Cloud [PyData DC]Building Serverless Machine Learning Models in the Cloud [PyData DC]
Building Serverless Machine Learning Models in the Cloud [PyData DC]
 
Introduction to Apache Beam
Introduction to Apache BeamIntroduction to Apache Beam
Introduction to Apache Beam
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
Async js
Async jsAsync js
Async js
 
"Production-ready Serverless Java Applications in 3 weeks" at AWS Community D...
"Production-ready Serverless Java Applications in 3 weeks" at AWS Community D..."Production-ready Serverless Java Applications in 3 weeks" at AWS Community D...
"Production-ready Serverless Java Applications in 3 weeks" at AWS Community D...
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje CrnjakJavantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
 
Big Data Day LA 2016/ Big Data Track - Portable Stream and Batch Processing w...
Big Data Day LA 2016/ Big Data Track - Portable Stream and Batch Processing w...Big Data Day LA 2016/ Big Data Track - Portable Stream and Batch Processing w...
Big Data Day LA 2016/ Big Data Track - Portable Stream and Batch Processing w...
 
Slick 3.0 functional programming and db side effects
Slick 3.0   functional programming and db side effectsSlick 3.0   functional programming and db side effects
Slick 3.0 functional programming and db side effects
 
Autoscaling near-persistent EBS
Autoscaling near-persistent EBSAutoscaling near-persistent EBS
Autoscaling near-persistent EBS
 
Tis the Season to Scale
Tis the Season to ScaleTis the Season to Scale
Tis the Season to Scale
 
Clovaを支える技術 機械学習配信基盤のご紹介
Clovaを支える技術 機械学習配信基盤のご紹介Clovaを支える技術 機械学習配信基盤のご紹介
Clovaを支える技術 機械学習配信基盤のご紹介
 
Intro stream processing.be meetup #1
Intro stream processing.be meetup #1Intro stream processing.be meetup #1
Intro stream processing.be meetup #1
 
Craft Beer & Clojure
Craft Beer & ClojureCraft Beer & Clojure
Craft Beer & Clojure
 
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
 

Destaque

The Future starts with a Promise
The Future starts with a PromiseThe Future starts with a Promise
The Future starts with a Promise
Alexandru Nedelcu
 
How effective is the combination of your music video, dvd digipak and print a...
How effective is the combination of your music video, dvd digipak and print a...How effective is the combination of your music video, dvd digipak and print a...
How effective is the combination of your music video, dvd digipak and print a...
Alex Chenery-Howes
 
Why Stories in Games Suck
Why Stories in Games SuckWhy Stories in Games Suck
Why Stories in Games Suck
Adrian Hon
 
Adopting Project Management 2 Say It Right
Adopting Project Management 2 Say It RightAdopting Project Management 2 Say It Right
Adopting Project Management 2 Say It Right
Joseph Andrade
 
Digital trends 2013
Digital trends 2013Digital trends 2013
Digital trends 2013
Adam Hassan
 
Presentation For Cnie
Presentation For CniePresentation For Cnie
Presentation For Cnie
guest07be80
 
External Business Presentation
External Business PresentationExternal Business Presentation
External Business Presentation
Callum Lee
 

Destaque (19)

The Future starts with a Promise
The Future starts with a PromiseThe Future starts with a Promise
The Future starts with a Promise
 
Miksi terveydenhuollon IT on rikki?
Miksi terveydenhuollon IT on rikki?Miksi terveydenhuollon IT on rikki?
Miksi terveydenhuollon IT on rikki?
 
How effective is the combination of your music video, dvd digipak and print a...
How effective is the combination of your music video, dvd digipak and print a...How effective is the combination of your music video, dvd digipak and print a...
How effective is the combination of your music video, dvd digipak and print a...
 
New to 90 or Nearly 90
New to 90 or Nearly 90New to 90 or Nearly 90
New to 90 or Nearly 90
 
Why Stories in Games Suck
Why Stories in Games SuckWhy Stories in Games Suck
Why Stories in Games Suck
 
Презентация для "Юридической клиники Вероники Сорокинайте"
Презентация для "Юридической клиники Вероники Сорокинайте"Презентация для "Юридической клиники Вероники Сорокинайте"
Презентация для "Юридической клиники Вероники Сорокинайте"
 
Mapa conceptual 2
Mapa conceptual   2Mapa conceptual   2
Mapa conceptual 2
 
Web 2.0 for schools
Web 2.0 for schoolsWeb 2.0 for schools
Web 2.0 for schools
 
A New Moment of Promise (translated in Portuguese)
A New Moment of Promise (translated in Portuguese)A New Moment of Promise (translated in Portuguese)
A New Moment of Promise (translated in Portuguese)
 
Score More Money Online: Five Simple Ways to Change the Game
Score More Money Online: Five Simple Ways to Change the GameScore More Money Online: Five Simple Ways to Change the Game
Score More Money Online: Five Simple Ways to Change the Game
 
Adopting Project Management 2 Say It Right
Adopting Project Management 2 Say It RightAdopting Project Management 2 Say It Right
Adopting Project Management 2 Say It Right
 
Google Analtyics - Everyone Says I Love You - Avery Cohen - Metrist Partners ...
Google Analtyics - Everyone Says I Love You - Avery Cohen - Metrist Partners ...Google Analtyics - Everyone Says I Love You - Avery Cohen - Metrist Partners ...
Google Analtyics - Everyone Says I Love You - Avery Cohen - Metrist Partners ...
 
Sponsored InMail 101
Sponsored InMail 101Sponsored InMail 101
Sponsored InMail 101
 
Digital trends 2013
Digital trends 2013Digital trends 2013
Digital trends 2013
 
Presentation For Cnie
Presentation For CniePresentation For Cnie
Presentation For Cnie
 
External Business Presentation
External Business PresentationExternal Business Presentation
External Business Presentation
 
Xplicit image 8
Xplicit image 8Xplicit image 8
Xplicit image 8
 
Web 2.0 y aprendizaje colaborativo
Web 2.0 y aprendizaje colaborativoWeb 2.0 y aprendizaje colaborativo
Web 2.0 y aprendizaje colaborativo
 
Vinterväghållning i Bäsna
Vinterväghållning i BäsnaVinterväghållning i Bäsna
Vinterväghållning i Bäsna
 

Semelhante a Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, ThoughtWorks - presented at Pune Scala Symposium 2014, ThoughtWorks

Lecture 1
Lecture 1Lecture 1
Lecture 1
Mr SMAK
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
Christophe Grand
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
jazoon13
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
Vinay H G
 

Semelhante a Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, ThoughtWorks - presented at Pune Scala Symposium 2014, ThoughtWorks (20)

Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Introduction To Design Patterns Class 4 Composition vs Inheritance
 Introduction To Design Patterns Class 4 Composition vs Inheritance Introduction To Design Patterns Class 4 Composition vs Inheritance
Introduction To Design Patterns Class 4 Composition vs Inheritance
 
Hi
HiHi
Hi
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Scalable game-servers-tgc
Scalable game-servers-tgcScalable game-servers-tgc
Scalable game-servers-tgc
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
 
Software + Babies
Software + BabiesSoftware + Babies
Software + Babies
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
Graphene – Microsoft SCOPE on Tez
Graphene – Microsoft SCOPE on Tez Graphene – Microsoft SCOPE on Tez
Graphene – Microsoft SCOPE on Tez
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless DreamsRainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
Rainbows, Unicorns, and other Fairy Tales in the Land of Serverless Dreams
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 

Mais de Thoughtworks

Mais de Thoughtworks (20)

Design System as a Product
Design System as a ProductDesign System as a Product
Design System as a Product
 
Designers, Developers & Dogs
Designers, Developers & DogsDesigners, Developers & Dogs
Designers, Developers & Dogs
 
Cloud-first for fast innovation
Cloud-first for fast innovationCloud-first for fast innovation
Cloud-first for fast innovation
 
More impact with flexible teams
More impact with flexible teamsMore impact with flexible teams
More impact with flexible teams
 
Culture of Innovation
Culture of InnovationCulture of Innovation
Culture of Innovation
 
Dual-Track Agile
Dual-Track AgileDual-Track Agile
Dual-Track Agile
 
Developer Experience
Developer ExperienceDeveloper Experience
Developer Experience
 
When we design together
When we design togetherWhen we design together
When we design together
 
Hardware is hard(er)
Hardware is hard(er)Hardware is hard(er)
Hardware is hard(er)
 
Customer-centric innovation enabled by cloud
 Customer-centric innovation enabled by cloud Customer-centric innovation enabled by cloud
Customer-centric innovation enabled by cloud
 
Amazon's Culture of Innovation
Amazon's Culture of InnovationAmazon's Culture of Innovation
Amazon's Culture of Innovation
 
When in doubt, go live
When in doubt, go liveWhen in doubt, go live
When in doubt, go live
 
Don't cross the Rubicon
Don't cross the RubiconDon't cross the Rubicon
Don't cross the Rubicon
 
Error handling
Error handlingError handling
Error handling
 
Your test coverage is a lie!
Your test coverage is a lie!Your test coverage is a lie!
Your test coverage is a lie!
 
Docker container security
Docker container securityDocker container security
Docker container security
 
Redefining the unit
Redefining the unitRedefining the unit
Redefining the unit
 
Technology Radar Webinar UK - Vol. 22
Technology Radar Webinar UK - Vol. 22Technology Radar Webinar UK - Vol. 22
Technology Radar Webinar UK - Vol. 22
 
A Tribute to Turing
A Tribute to TuringA Tribute to Turing
A Tribute to Turing
 
Rsa maths worked out
Rsa maths worked outRsa maths worked out
Rsa maths worked out
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)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 MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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 2024The 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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Promise of a better future by Rahul Goma Phulore and Pooja Akshantal, ThoughtWorks - presented at Pune Scala Symposium 2014, ThoughtWorks

  • 1. Promise of a better future Pooja Akshantal Rahul Goma Phulore
  • 3. What we are going to talk about • How concurrency and parallelism are different ideas • Why concurrency is important • Futures and promises • DEMO! • Pitfalls
  • 4. Concurrency ≠ Parallelism Concurrency is a program- structuring technique in which there are multiple threads of control A parallel program is one that uses a multiplicity of computational hardware (e.g. multiple processor cores) Structure Execution Dealing with lots of things at once Doing lots of things at once
  • 5. Orthogonality illustrated Javascript promises, Python generators Java and Scala futures Well… lots of things Parallel collections
  • 7. Age of multicore • Multicore has become a norm! • Need to exploit parallelism to perform • Good concurrency abstractions a way to get there
  • 9. Futures and promises • Can be thought of as a single concurrency abstraction
  • 10. Future ≈ Cheap thread • Futures are multiplexed dynamically onto threads as needed. • Managed by ExecutionContext. • It’s practical to have hundreds of thousands going at once. • Spawn away!
  • 12. Async and non-blocking • Goal: Do not block current thread while waiting for the result of the future. • Callbacks: – Register callback which is invoked asynchronously when future is completed – Async computations do not block
  • 14. There is a solution! • Higher-order functions / combinators • for-comprehensions • Other abstractions
  • 15. Running example • Collect statistics for a facebook page • For every post on the page: – Collect all likes – Collect all comments • Aggregate results into popularity score
  • 17. Other parallels • Error recovery combinators – recover – recoverWith • Collection operations – map: (Seq[A], A ⇒ B) ⇒ Seq[B] mapF: (Seq[A], A ⇒ Future[B]) ⇒ Future[Seq[B]] – filter: (Seq[A], A ⇒ Boolean) ⇒ Seq[A] filterF: (Seq[A], A ⇒ Future[Boolean]) ⇒ Future[Seq[A]]
  • 18. Pitfalls • Interactions with thread-unsafe libraries • ThreadLocal variables • Retries, time-outs not very natural • Simpler than other concurrency models in many ways, but still incur some cognitive cost
  • 19. Credits • Heather Miller, for her material on relationship between futures and promises • Simon Marlow and Rob Pike, for their material on concurrency and parallelism • Josh Suereth, for his Github example (Inspiration for our facebook example) • Scala, Play, and Akka teams for all their amazing work