SlideShare a Scribd company logo
1 of 62
Download to read offline
Asynctweeter :: @RobertWPearce
github :: rpearce
email :: me@robertwpearce.com
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 1
about me
Hi, I'm Robert
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
• Started out at Jack Russell Software w/ Tom Wilson in 2011
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
• Started out at Jack Russell Software w/ Tom Wilson in 2011
• Currently with Articulate, the e-learning software company
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
• Started out at Jack Russell Software w/ Tom Wilson in 2011
• Currently with Articulate, the e-learning software company
• Work with FP in JS all day
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
• Started out at Jack Russell Software w/ Tom Wilson in 2011
• Currently with Articulate, the e-learning software company
• Work with FP in JS all day
• Learn Haskell (λ) in my free time
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
about me
Hi, I'm Robert
• My kiwi wife & I have just moved back from New Zealand
• Started out at Jack Russell Software w/ Tom Wilson in 2011
• Currently with Articulate, the e-learning software company
• Work with FP in JS all day
• Learn Haskell (λ) in my free time
• Pretend to know what I'm doing
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
Question:
what are we going to do?
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 3
Answer:
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
Answer:
• read & transform files with Promises
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
Answer:
• read & transform files with Promises
•
!
but with Asyncs
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
Answer:
• read & transform files with Promises
•
!
but with Asyncs
• ...this is our Friday night
✨
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
Use case?
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
• make it easy to bootstrap a new package
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
• make it easy to bootstrap a new package
• solution:
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
• make it easy to bootstrap a new package
• solution:
1. make templates
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
• make it easy to bootstrap a new package
• solution:
1. make templates
2. make CLI app to collect options
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
Use case?
• reactjs component library monorepo
• make it easy to bootstrap a new package
• solution:
1. make templates
2. make CLI app to collect options
3. replace dummy template bits with options
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.readFile
import fs from 'fs'
fs.readFile('/path/to/file', 'utf8', (err, contents) => {
if (err) {
throw err
}
console.log(contents)
})
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: fs.promises.readFile
import fs, { promises as fsp } from 'fs'
fsp
.readFile('/path/to/file', 'utf8')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
refresher: async/await
import fs, { promises as fsp } from 'fs'
const toUpper = x => x.toUpperCase()
const readFileAndTransform = async (fn, f) => {
const contents = await fsp.readFile(f, 'utf8')
return fn(contents)
}
readFileAndTransform(toUpper, '/path/to/file')
.then(console.log)
.catch(console.error)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
drawbacks with callbacks
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
drawbacks with callbacks
• asynchronous callbacks (like in fs.readFile) don't return a
value to caller
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
drawbacks with callbacks
• asynchronous callbacks (like in fs.readFile) don't return a
value to caller
• (not composable...easily)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
drawbacks with callbacks
• asynchronous callbacks (like in fs.readFile) don't return a
value to caller
• (not composable...easily)
• don't work well with control flow (if (fs.readFile(...)))
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
drawbacks with callbacks
• asynchronous callbacks (like in fs.readFile) don't return a
value to caller
• (not composable...easily)
• don't work well with control flow (if (fs.readFile(...)))
• inevitably nest ---->
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 10
Callbacks are the narrowing spiral
staircase to hell. They are control
flow as designed by M.C. Escher.
— Dr. Boolean, Professor Frisby's Mostly Adequate Guide to
Functional Programming
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 11
Promises are awesome! But...
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
Promises are awesome! But...
• values; not computations (like a function or other structure)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
Promises are awesome! But...
• values; not computations (like a function or other structure)
• don't support cancellation
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
Promises are awesome! But...
• values; not computations (like a function or other structure)
• don't support cancellation
• don't support nesting
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
Promises are awesome! But...
• values; not computations (like a function or other structure)
• don't support cancellation
• don't support nesting
• impure
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
!
might not phase you at all
i still ❤ callbacks & promises
but let's see a different tool!
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 13
break out neovim & friends
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 14
what exactly is an Async (aka Task)?
• "lazy Sum Type that implements an asynchronous control
structure"
• will not execute until needed
• keeps track of its internals (
!
for cleanup & cancellation)
Async e a = Rejected e | Resolved a
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 15
example in the wild wrapping the axios library
https://github.com/articulate/asyncios
// POST request
asyncios({
method: 'POST',
url: '/user?ID=12345',
data: { firstName: 'Fred', lastName: 'Flinstone' },
})
.fork(
error => console.log(error),
response => console.log(response)
)
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 16
what is crocks?
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 17
what is ramda?
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 18
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 19
where can i learn more?
• https://crocks.dev/docs/crocks/Async.html
• https://gitter.im/crocksjs/crocks
• TheEvilSoft's youtube channel
• Professor Frisby's Mostly Adequate Guide to Functional Programming
• https://folktale.origamitower.com/api/v2.3.0/en/
folktale.concurrency.task.html
• Functional Programming in JavaScript with Ramda.js
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 20
Asynctweeter :: @RobertWPearce
github :: rpearce
email :: me@robertwpearce.com
@RobertWPearce | rwp.im | 2019-08-23 charleston.js 21

More Related Content

What's hot

GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemTommaso Visconti
 
Git inter-snapshot public
Git  inter-snapshot publicGit  inter-snapshot public
Git inter-snapshot publicSeongJae Park
 
Rotzy - Building an iPhone Photo Sharing App on Google App Engine
Rotzy - Building an iPhone Photo Sharing App on Google App EngineRotzy - Building an iPhone Photo Sharing App on Google App Engine
Rotzy - Building an iPhone Photo Sharing App on Google App Enginegeehwan
 
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013Puppet
 
DO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCSDO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCSSeongJae Park
 
성장을 좋아하는 사람이, 성장하고 싶은 사람에게
성장을 좋아하는 사람이, 성장하고 싶은 사람에게성장을 좋아하는 사람이, 성장하고 싶은 사람에게
성장을 좋아하는 사람이, 성장하고 싶은 사람에게Seongyun Byeon
 
Version Control and Git - GitHub Workshop
Version Control and Git - GitHub WorkshopVersion Control and Git - GitHub Workshop
Version Control and Git - GitHub WorkshopAll Things Open
 
Node Tools For Your Grails Toolbox - Gr8Conf 2013
Node Tools For Your Grails Toolbox - Gr8Conf 2013Node Tools For Your Grails Toolbox - Gr8Conf 2013
Node Tools For Your Grails Toolbox - Gr8Conf 2013zanthrash
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processingAnton Arhipov
 

What's hot (9)

GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
 
Git inter-snapshot public
Git  inter-snapshot publicGit  inter-snapshot public
Git inter-snapshot public
 
Rotzy - Building an iPhone Photo Sharing App on Google App Engine
Rotzy - Building an iPhone Photo Sharing App on Google App EngineRotzy - Building an iPhone Photo Sharing App on Google App Engine
Rotzy - Building an iPhone Photo Sharing App on Google App Engine
 
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
PuppetDB: New Adventures in Higher-Order Automation - PuppetConf 2013
 
DO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCSDO YOU WANT TO USE A VCS
DO YOU WANT TO USE A VCS
 
성장을 좋아하는 사람이, 성장하고 싶은 사람에게
성장을 좋아하는 사람이, 성장하고 싶은 사람에게성장을 좋아하는 사람이, 성장하고 싶은 사람에게
성장을 좋아하는 사람이, 성장하고 싶은 사람에게
 
Version Control and Git - GitHub Workshop
Version Control and Git - GitHub WorkshopVersion Control and Git - GitHub Workshop
Version Control and Git - GitHub Workshop
 
Node Tools For Your Grails Toolbox - Gr8Conf 2013
Node Tools For Your Grails Toolbox - Gr8Conf 2013Node Tools For Your Grails Toolbox - Gr8Conf 2013
Node Tools For Your Grails Toolbox - Gr8Conf 2013
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processing
 

Similar to From Promises & async/await to Async Algebraic Data Types

SOOCon24 - Showing that you care about security - OpenSSF Scorecards
SOOCon24 - Showing that you care about security - OpenSSF ScorecardsSOOCon24 - Showing that you care about security - OpenSSF Scorecards
SOOCon24 - Showing that you care about security - OpenSSF ScorecardsChris Swan
 
Genomics Is Not Special: Towards Data Intensive Biology
Genomics Is Not Special: Towards Data Intensive BiologyGenomics Is Not Special: Towards Data Intensive Biology
Genomics Is Not Special: Towards Data Intensive BiologyUri Laserson
 
React, Powered by WebAssembly
React, Powered by WebAssemblyReact, Powered by WebAssembly
React, Powered by WebAssemblyJay Phelps
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from DataMosky Liu
 
It’s about time to embrace Streams
It’s about time to embrace StreamsIt’s about time to embrace Streams
It’s about time to embrace StreamsLuciano Mammino
 
Downloading a Billion Files in Python
Downloading a Billion Files in PythonDownloading a Billion Files in Python
Downloading a Billion Files in PythonJames Saryerwinnie
 
Filesystems Lisbon 2018
Filesystems Lisbon 2018Filesystems Lisbon 2018
Filesystems Lisbon 2018Frank de Jonge
 
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015CODE BLUE
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line toolsEric Wilson
 
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAwesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAjeet Singh Raina
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11Elizabeth Smith
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Samuel Lampa
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaLin Yo-An
 
lwref: insane idea on reference counting
lwref: insane idea on reference countinglwref: insane idea on reference counting
lwref: insane idea on reference countingGleb Smirnoff
 
CPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolsCPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolscharsbar
 

Similar to From Promises & async/await to Async Algebraic Data Types (20)

ReactPHP
ReactPHPReactPHP
ReactPHP
 
SOOCon24 - Showing that you care about security - OpenSSF Scorecards
SOOCon24 - Showing that you care about security - OpenSSF ScorecardsSOOCon24 - Showing that you care about security - OpenSSF Scorecards
SOOCon24 - Showing that you care about security - OpenSSF Scorecards
 
Genomics Is Not Special: Towards Data Intensive Biology
Genomics Is Not Special: Towards Data Intensive BiologyGenomics Is Not Special: Towards Data Intensive Biology
Genomics Is Not Special: Towards Data Intensive Biology
 
Advanced I/O in browser
Advanced I/O in browserAdvanced I/O in browser
Advanced I/O in browser
 
React, Powered by WebAssembly
React, Powered by WebAssemblyReact, Powered by WebAssembly
React, Powered by WebAssembly
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
It’s about time to embrace Streams
It’s about time to embrace StreamsIt’s about time to embrace Streams
It’s about time to embrace Streams
 
Downloading a Billion Files in Python
Downloading a Billion Files in PythonDownloading a Billion Files in Python
Downloading a Billion Files in Python
 
Filesystems Lisbon 2018
Filesystems Lisbon 2018Filesystems Lisbon 2018
Filesystems Lisbon 2018
 
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015
Defeating firefox by Muneaki Nishimunea - CODE BLUE 2015
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAwesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
 
Sprockets
SprocketsSprockets
Sprockets
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
Os Treat
Os TreatOs Treat
Os Treat
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
lwref: insane idea on reference counting
lwref: insane idea on reference countinglwref: insane idea on reference counting
lwref: insane idea on reference counting
 
CPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its toolsCPANTS: Kwalitative website and its tools
CPANTS: Kwalitative website and its tools
 

More from Robert Pearce

How to Lose Functional Programming at Work
How to Lose Functional Programming at WorkHow to Lose Functional Programming at Work
How to Lose Functional Programming at WorkRobert Pearce
 
hakyll – haskell static site generator
hakyll – haskell static site generatorhakyll – haskell static site generator
hakyll – haskell static site generatorRobert Pearce
 
Behaviour & Your Team
Behaviour & Your TeamBehaviour & Your Team
Behaviour & Your TeamRobert Pearce
 
Static sites with react
Static sites with reactStatic sites with react
Static sites with reactRobert Pearce
 
React.js Basics - ConvergeSE 2015
React.js Basics - ConvergeSE 2015React.js Basics - ConvergeSE 2015
React.js Basics - ConvergeSE 2015Robert Pearce
 
JavaScript 101 - Class 2
JavaScript 101 - Class 2JavaScript 101 - Class 2
JavaScript 101 - Class 2Robert Pearce
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1Robert Pearce
 

More from Robert Pearce (7)

How to Lose Functional Programming at Work
How to Lose Functional Programming at WorkHow to Lose Functional Programming at Work
How to Lose Functional Programming at Work
 
hakyll – haskell static site generator
hakyll – haskell static site generatorhakyll – haskell static site generator
hakyll – haskell static site generator
 
Behaviour & Your Team
Behaviour & Your TeamBehaviour & Your Team
Behaviour & Your Team
 
Static sites with react
Static sites with reactStatic sites with react
Static sites with react
 
React.js Basics - ConvergeSE 2015
React.js Basics - ConvergeSE 2015React.js Basics - ConvergeSE 2015
React.js Basics - ConvergeSE 2015
 
JavaScript 101 - Class 2
JavaScript 101 - Class 2JavaScript 101 - Class 2
JavaScript 101 - Class 2
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

From Promises & async/await to Async Algebraic Data Types

  • 1. Asynctweeter :: @RobertWPearce github :: rpearce email :: me@robertwpearce.com @RobertWPearce | rwp.im | 2019-08-23 charleston.js 1
  • 2. about me Hi, I'm Robert @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 3. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 4. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand • Started out at Jack Russell Software w/ Tom Wilson in 2011 @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 5. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand • Started out at Jack Russell Software w/ Tom Wilson in 2011 • Currently with Articulate, the e-learning software company @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 6. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand • Started out at Jack Russell Software w/ Tom Wilson in 2011 • Currently with Articulate, the e-learning software company • Work with FP in JS all day @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 7. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand • Started out at Jack Russell Software w/ Tom Wilson in 2011 • Currently with Articulate, the e-learning software company • Work with FP in JS all day • Learn Haskell (λ) in my free time @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 8. about me Hi, I'm Robert • My kiwi wife & I have just moved back from New Zealand • Started out at Jack Russell Software w/ Tom Wilson in 2011 • Currently with Articulate, the e-learning software company • Work with FP in JS all day • Learn Haskell (λ) in my free time • Pretend to know what I'm doing @RobertWPearce | rwp.im | 2019-08-23 charleston.js 2
  • 9. Question: what are we going to do? @RobertWPearce | rwp.im | 2019-08-23 charleston.js 3
  • 10. Answer: @RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
  • 11. Answer: • read & transform files with Promises @RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
  • 12. Answer: • read & transform files with Promises • ! but with Asyncs @RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
  • 13. Answer: • read & transform files with Promises • ! but with Asyncs • ...this is our Friday night ✨ @RobertWPearce | rwp.im | 2019-08-23 charleston.js 4
  • 14. Use case? @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 15. Use case? • reactjs component library monorepo @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 16. Use case? • reactjs component library monorepo • make it easy to bootstrap a new package @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 17. Use case? • reactjs component library monorepo • make it easy to bootstrap a new package • solution: @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 18. Use case? • reactjs component library monorepo • make it easy to bootstrap a new package • solution: 1. make templates @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 19. Use case? • reactjs component library monorepo • make it easy to bootstrap a new package • solution: 1. make templates 2. make CLI app to collect options @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 20. Use case? • reactjs component library monorepo • make it easy to bootstrap a new package • solution: 1. make templates 2. make CLI app to collect options 3. replace dummy template bits with options @RobertWPearce | rwp.im | 2019-08-23 charleston.js 5
  • 21. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 22. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 23. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 24. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 25. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 26. refresher: fs.readFile import fs from 'fs' fs.readFile('/path/to/file', 'utf8', (err, contents) => { if (err) { throw err } console.log(contents) }) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 6
  • 27. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 28. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 29. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 30. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 31. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 32. refresher: fs.promises.readFile import fs, { promises as fsp } from 'fs' fsp .readFile('/path/to/file', 'utf8') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 7
  • 33. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 34. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 35. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 36. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 37. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 38. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 39. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 40. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 41. refresher: async/await import fs, { promises as fsp } from 'fs' const toUpper = x => x.toUpperCase() const readFileAndTransform = async (fn, f) => { const contents = await fsp.readFile(f, 'utf8') return fn(contents) } readFileAndTransform(toUpper, '/path/to/file') .then(console.log) .catch(console.error) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 8
  • 42. drawbacks with callbacks @RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
  • 43. drawbacks with callbacks • asynchronous callbacks (like in fs.readFile) don't return a value to caller @RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
  • 44. drawbacks with callbacks • asynchronous callbacks (like in fs.readFile) don't return a value to caller • (not composable...easily) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
  • 45. drawbacks with callbacks • asynchronous callbacks (like in fs.readFile) don't return a value to caller • (not composable...easily) • don't work well with control flow (if (fs.readFile(...))) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
  • 46. drawbacks with callbacks • asynchronous callbacks (like in fs.readFile) don't return a value to caller • (not composable...easily) • don't work well with control flow (if (fs.readFile(...))) • inevitably nest ----> @RobertWPearce | rwp.im | 2019-08-23 charleston.js 9
  • 47. @RobertWPearce | rwp.im | 2019-08-23 charleston.js 10
  • 48. Callbacks are the narrowing spiral staircase to hell. They are control flow as designed by M.C. Escher. — Dr. Boolean, Professor Frisby's Mostly Adequate Guide to Functional Programming @RobertWPearce | rwp.im | 2019-08-23 charleston.js 11
  • 49. Promises are awesome! But... @RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
  • 50. Promises are awesome! But... • values; not computations (like a function or other structure) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
  • 51. Promises are awesome! But... • values; not computations (like a function or other structure) • don't support cancellation @RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
  • 52. Promises are awesome! But... • values; not computations (like a function or other structure) • don't support cancellation • don't support nesting @RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
  • 53. Promises are awesome! But... • values; not computations (like a function or other structure) • don't support cancellation • don't support nesting • impure @RobertWPearce | rwp.im | 2019-08-23 charleston.js 12
  • 54. ! might not phase you at all i still ❤ callbacks & promises but let's see a different tool! @RobertWPearce | rwp.im | 2019-08-23 charleston.js 13
  • 55. break out neovim & friends @RobertWPearce | rwp.im | 2019-08-23 charleston.js 14
  • 56. what exactly is an Async (aka Task)? • "lazy Sum Type that implements an asynchronous control structure" • will not execute until needed • keeps track of its internals ( ! for cleanup & cancellation) Async e a = Rejected e | Resolved a @RobertWPearce | rwp.im | 2019-08-23 charleston.js 15
  • 57. example in the wild wrapping the axios library https://github.com/articulate/asyncios // POST request asyncios({ method: 'POST', url: '/user?ID=12345', data: { firstName: 'Fred', lastName: 'Flinstone' }, }) .fork( error => console.log(error), response => console.log(response) ) @RobertWPearce | rwp.im | 2019-08-23 charleston.js 16
  • 58. what is crocks? @RobertWPearce | rwp.im | 2019-08-23 charleston.js 17
  • 59. what is ramda? @RobertWPearce | rwp.im | 2019-08-23 charleston.js 18
  • 60. @RobertWPearce | rwp.im | 2019-08-23 charleston.js 19
  • 61. where can i learn more? • https://crocks.dev/docs/crocks/Async.html • https://gitter.im/crocksjs/crocks • TheEvilSoft's youtube channel • Professor Frisby's Mostly Adequate Guide to Functional Programming • https://folktale.origamitower.com/api/v2.3.0/en/ folktale.concurrency.task.html • Functional Programming in JavaScript with Ramda.js @RobertWPearce | rwp.im | 2019-08-23 charleston.js 20
  • 62. Asynctweeter :: @RobertWPearce github :: rpearce email :: me@robertwpearce.com @RobertWPearce | rwp.im | 2019-08-23 charleston.js 21