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

Getting started with ReactPHP – Pushing real-time data to the browser (PHPBenelux20)

Getting started with ReactPHP – Pushing real-time data to the browser (PHPBenelux20)

Think about PHP for a few seconds… What came to mind? It’s very likely you thought about your average product catalog, a blogging platform, or how the platform is inferior to things like Node.js. But wait, it’s 2020! What if I told you PHP’s huge ecosystem has way more to offer and PHP is not inferior at all to its evil cousin Node.js?

In this talk you will learn about the core concepts of async PHP and why you too should care about ReactPHP being a real thing. The talk has a strong focus on sparking the idea that PHP can be way faster and more versatile than you probably thought. Bring along an open mind, and through lots of interesting examples and live demos learn why what sounds crazy at first might soon be a valuable addition in your toolbox.

You’re already familiar with PHP and want to learn what ReactPHP is all about? Then this talk is for you! We will start from scratch and see what it takes to build an application that pushes data from your command line to your browser in real-time. You’re invited to join the interactive demos or lean back and learn more about why an event-driven approach might be the next big thing in making your application faster and more responsive.

---

These slides were used as part of a presentation at @phpbenelux. The full presentation took 60min with basic project setup, getting started with ReactPHP's core components and eventually implementing an HTTP server using Server-Sent Events (EventSource).

Resulting source code can be found here: https://gist.github.com/clue/c426bcee9c7767157085d6b881204998

Christian Lück
PRO

January 25, 2020
Tweet

More Decks by Christian Lück

Other Decks in Programming

Transcript

  1. getting started with ReactPHP
    pushing real-time data to the browser
    @another_clue

    View Slide

  2. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    2

    View Slide

  3. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    3

    View Slide

  4. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    4

    View Slide

  5. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    5

    View Slide

  6. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    6

    View Slide

  7. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    7

    View Slide

  8. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    - Streaming HTTP
    8

    View Slide

  9. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    - Streaming HTTP
    - Chat bots
    9

    View Slide

  10. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    - Streaming HTTP
    - Chat bots
    - interactive CLI tools
    10

    View Slide

  11. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    - Streaming HTTP
    - Chat bots
    - interactive CLI tools
    - desktop GUI
    11

    View Slide

  12. @another_clue
    Agenda
    12
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - real time data
    - Streaming HTTP
    - Chat bots
    - interactive CLI tools
    - desktop GUI
    - Conclusions

    View Slide

  13. @another_clue
    really?
    13

    View Slide

  14. @another_clue
    this is a getting started guide
    14

    View Slide

  15. @another_clue
    pushing real-time data
    to the browser
    15

    View Slide

  16. @another_clue
    I encourage feedback,
    questions + suggestions
    16

    View Slide

  17. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - conclusions
    17

    View Slide

  18. @another_clue
    Agenda
    - Hello!
    - Introduction to async PHP with ReactPHP
    - event loops
    - streaming data
    - sockets
    - promises
    - conclusions
    18
    examples and demo time!

    View Slide

  19. @another_clue
    Hello!
    19

    View Slide

  20. @another_clue
    $ whoami
    20

    View Slide

  21. @another_clue
    $ whoami
    Christian Lück
    21

    View Slide

  22. @another_clue
    $ whoami
    Christian Lück
    22

    View Slide

  23. @another_clue
    $ whoami
    Christian Lueck
    23

    View Slide

  24. @another_clue
    $ whoami
    Christian Lueck
    24

    View Slide

  25. @another_clue
    $ whoami
    Christian Lueck
    @clue
    25

    View Slide

  26. @another_clue
    $ whoami
    Christian Lueck
    @another_clue
    26

    View Slide

  27. @another_clue
    $ whoami
    Christian Lueck
    @another_clue
    passionate about pushing the limits
    27

    View Slide

  28. @another_clue
    $ whoami
    Christian Lueck
    @another_clue
    passionate about pushing the limits
    freelance software engineer 28

    View Slide

  29. @another_clue
    Who are you?
    29
    now that you know me…

    View Slide

  30. @another_clue
    Who are you?
    30
    now that you know me…
    - PHP developers?
    - architecs / engineers?

    View Slide

  31. @another_clue
    Who are you?
    31
    now that you know me…
    - PHP developers?
    - architecs / engineers?
    - know React?

    View Slide

  32. @another_clue
    PHP, the web of the ‘90s?
    32

    View Slide

  33. @another_clue
    PHP and the web of the ‘90s
    33

    View Slide

  34. @another_clue
    PHP and the web of the ‘90s
    34
    Apache
    Client PHP MySQL

    View Slide

  35. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    35
    Apache
    Client PHP MySQL

    View Slide

  36. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    Request-Response-Cycle
    36
    Apache
    Client PHP MySQL

    View Slide

  37. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    Request-Response-Cycle
    PHP is too slow? 37
    Apache
    Client PHP MySQL

    View Slide

  38. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    Request-Response-Cycle
    PHP is too slow? 38
    Apache
    Client MySQL
    FPM
    PHP
    PHP

    View Slide

  39. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    Request-Response-Cycle
    PHP is too slow? 39
    nginx
    Client MySQL
    FPM
    PHP
    PHP

    View Slide

  40. @another_clue
    PHP and the web of the ‘90s
    traditional LAMP stack
    Request-Response-Cycle
    PHP is too slow? 40
    nginx
    Client
    FPM
    PHP
    PHP memcache
    MySQL

    View Slide

  41. @another_clue
    PHP may not be pretty…
    41

    View Slide

  42. @another_clue
    PHP may not be pretty…
    but it gets the job done!
    42

    View Slide

  43. @another_clue
    Knock knock!
    Who’s there?
    43

    View Slide

  44. @another_clue
    Knock knock!
    2020!
    Who’s there?
    44

    View Slide

  45. @another_clue
    Knock knock!
    2020!
    - Separation of concerns
    (Frontend↔Backend)
    - HTTP APIs (RESTful)
    - Integration with 3rd parties
    - Live-Data (ticker)
    - CLI tools
    Who’s there?
    45

    View Slide

  46. @another_clue
    Knock knock!
    2020!
    - Separation of concerns
    (Frontend↔Backend)
    - HTTP APIs (RESTful)
    - Integration with 3rd parties
    - Live-Data (ticker)
    - CLI tools
    Who’s there?
    46

    View Slide

  47. @another_clue
    Node.js
    47

    View Slide

  48. @another_clue
    Node.js
    48
    good fit, huge ecosystem

    View Slide

  49. @another_clue
    Node.js
    49
    good fit, huge ecosystem
    interesting concepts

    View Slide

  50. @another_clue
    Node.js
    50
    good fit, huge ecosystem
    interesting concepts
    npm install…

    View Slide

  51. @another_clue
    nodejs?
    51

    View Slide

  52. @another_clue
    no js!
    52

    View Slide

  53. @another_clue
    Everybody’s favorite language…
    53

    View Slide

  54. @another_clue
    PHP
    54

    View Slide

  55. @another_clue
    PHP
    55
    gets the job done

    View Slide

  56. @another_clue
    PHP
    56
    gets the job done
    widespread usage

    View Slide

  57. @another_clue
    PHP
    57
    gets the job done
    widespread usage
    if PHP can do it…

    View Slide

  58. @another_clue
    Enter React!
    58

    View Slide

  59. @another_clue 59

    View Slide

  60. @another_clue
    The other React™
    60

    View Slide

  61. @another_clue
    The REAL React™
    61

    View Slide

  62. @another_clue 62

    View Slide

  63. @another_clue
    What is React?
    63

    View Slide

  64. @another_clue
    What is React?
    non-blocking I/O
    64

    View Slide

  65. @another_clue
    What is React?
    non-blocking I/O
    event-driven
    65

    View Slide

  66. @another_clue
    What is React?
    non-blocking I/O
    event-driven
    async
    66

    View Slide

  67. @another_clue
    100%
    67

    View Slide

  68. @another_clue
    100%
    pure PHP
    68

    View Slide

  69. @another_clue
    100%
    pure PHP
    no extensions
    69

    View Slide

  70. @another_clue
    100%
    pure PHP
    no extensions
    no magic
    70

    View Slide

  71. @another_clue
    What does that even mean?!
    71

    View Slide

  72. @another_clue
    the idea
    72

    View Slide

  73. @another_clue
    calculations are fast
    73
    the idea

    View Slide

  74. @another_clue
    calculations are fast
    I/O is slow
    74
    the idea

    View Slide

  75. @another_clue 75
    Source: Latency Numbers Every Programmer Should Know: https://gist.github.com/jboner/2841832
    CPU vs I/O

    View Slide

  76. @another_clue
    I/O is everywhere
    76

    View Slide

  77. @another_clue
    I/O is everywhere
    third party HTTP APIs (RESTful, SOAP, you name it…)
    77

    View Slide

  78. @another_clue
    I/O is everywhere
    third party HTTP APIs (RESTful, SOAP, you name it…)
    mysql, postgres
    78

    View Slide

  79. @another_clue
    I/O is everywhere
    third party HTTP APIs (RESTful, SOAP, you name it…)
    mysql, postgres
    filesystem I/O (session files)
    79

    View Slide

  80. @another_clue
    I/O is everywhere
    third party HTTP APIs (RESTful, SOAP, you name it…)
    mysql, postgres
    filesystem I/O (session files)
    redis, memcache 80

    View Slide

  81. @another_clue
    I/O is slow!
    81

    View Slide

  82. @another_clue
    I/O is slow!
    So why wait?
    82

    View Slide

  83. @another_clue
    This is React
    83

    View Slide

  84. @another_clue
    This is React
    84
    Start multiple I/O operations (non-blocking)

    View Slide

  85. @another_clue
    This is React
    85
    Start multiple I/O operations (non-blocking)
    Get notified when something happens (react)

    View Slide

  86. @another_clue
    This is React
    86
    Start multiple I/O operations (non-blocking)
    Get notified when something happens (react)
    Don’t waste time waiting

    View Slide

  87. @another_clue
    What React is not
    87

    View Slide

  88. @another_clue
    What React is not
    React is not black magic / vodoo
    88

    View Slide

  89. @another_clue
    What React is not
    React is not black magic / vodoo
    React is not a framework
    89

    View Slide

  90. @another_clue
    What React is not
    React is not black magic / vodoo
    React is not a framework
    React is not the new buzz
    90

    View Slide

  91. @another_clue
    React core components
    91

    View Slide

  92. @another_clue
    event loop
    92

    View Slide

  93. @another_clue
    Event loop
    Consumers
    - THE core, low-level component
    93

    View Slide

  94. @another_clue
    Event loop
    Consumers
    - THE core, low-level component
    - Create an instance
    - Just use the Factory
    - Additional extensions for bigger payloads
    - something inbetween…
    - just pass the $loop around
    - Start running
    - keeps running forever
    - unless stopped or done
    94

    View Slide

  95. @another_clue
    Event loop
    Consumers
    - THE core, low-level component
    - Create an instance
    - Just use the Factory
    - Additional extensions for bigger payloads
    - something inbetween…
    - just pass the $loop around
    - Start running
    - keeps running forever
    - unless stopped or done
    95

    View Slide

  96. @another_clue
    Event loop
    Implementors
    - Reactor pattern (hence the name)
    96

    View Slide

  97. @another_clue
    Event loop
    Implementors
    - Reactor pattern (hence the name)
    - start timers
    - once
    - periodic
    - ticks
    97

    View Slide

  98. @another_clue
    Event loop
    Implementors
    - Reactor pattern (hence the name)
    - start timers
    - once
    - periodic
    - ticks
    98

    View Slide

  99. @another_clue
    Event loop
    Implementors
    - Reactor pattern (hence the name)
    - start timers
    - once
    - periodic
    - ticks
    99

    View Slide

  100. @another_clue
    Event loop
    Implementors
    - Reactor pattern (hence the name)
    - start timers
    - once
    - periodic
    - ticks
    - plus wait for stream resources to become
    - readable
    - writable
    100

    View Slide

  101. @another_clue
    streaming data
    101

    View Slide

  102. @another_clue
    Streams
    - Process large strings in chunks as they happen (think downloads)
    - Types
    - Readable (e.g. STDIN pipe)
    - Writable (e.g. STDOUT pipe)
    - Duplex (e.g. TCP/IP connection)
    102

    View Slide

  103. @another_clue
    Stream interfaces and events
    103

    View Slide

  104. @another_clue
    Stream interfaces and events
    104

    View Slide

  105. @another_clue
    Stream interfaces and events
    105

    View Slide

  106. @another_clue
    sockets
    106

    View Slide

  107. @another_clue
    Sockets
    107
    - Streams, but over the network

    View Slide

  108. @another_clue
    Sockets
    108
    - Streams, but over the network
    - servers listen
    - clients connect

    View Slide

  109. @another_clue
    Sockets
    109
    - Streams, but over the network
    - servers listen
    - clients connect
    - Focus on TCP/IP (UDP etc. also possible)

    View Slide

  110. @another_clue
    Sockets
    110
    - Streams, but over the network
    - servers listen
    - clients connect
    - Focus on TCP/IP (UDP etc. also possible)

    View Slide

  111. @another_clue
    Sockets
    111
    - Streams, but over the network
    - servers listen
    - clients connect
    - Focus on TCP/IP (UDP etc. also possible)

    View Slide

  112. @another_clue
    Sockets
    112
    - Streams, but over the network
    - servers listen
    - clients connect
    - Focus on TCP/IP (UDP etc. also possible)

    View Slide

  113. @another_clue
    Sockets in practice
    113

    View Slide

  114. @another_clue
    Sockets in practice
    - implementation detail
    114

    View Slide

  115. @another_clue
    Sockets in practice
    - implementation detail
    - higher level protocols (HTTP anybody)
    115

    View Slide

  116. @another_clue
    Sockets in practice
    - implementation detail
    - higher level protocols (HTTP anybody)
    - higher level concepts (RESTful etc.)
    116

    View Slide

  117. @another_clue
    Sockets in practice
    - implementation detail
    - higher level protocols (HTTP anybody)
    - higher level concepts (RESTful etc.)
    - higher level APIs (SDKs, API clients etc.)
    117

    View Slide

  118. @another_clue
    Sockets in practice
    - implementation detail
    - higher level protocols (HTTP anybody)
    - higher level concepts (RESTful etc.)
    - higher level APIs (SDKs, API clients etc.)
    - Concepts still apply, details are hidden
    118

    View Slide

  119. @another_clue
    promises
    119

    View Slide

  120. @another_clue
    Promises
    - Placeholder for a single future result
    - Possible states:
    - pending
    - fulfilled (successfully resolved)
    - rejected (Exception occured)
    120

    View Slide

  121. @another_clue
    Promise API
    121

    View Slide

  122. @another_clue
    Promise API
    122

    View Slide

  123. @another_clue
    Promise API usage
    123

    View Slide

  124. @another_clue
    Promise API usage
    124

    View Slide

  125. @another_clue
    Promise API usage
    125

    View Slide

  126. @another_clue
    Promises in practice
    -
    126

    View Slide

  127. @another_clue
    Promises in practice
    - Everywhere!
    127

    View Slide

  128. @another_clue
    Promises in practice
    - Everywhere!
    - react/socket
    - clue/buzz-react
    - clue/packagist-react
    - clue/redis-react
    - react/mysql
    - …
    128

    View Slide

  129. @another_clue
    HTTP streaming
    129

    View Slide

  130. @another_clue
    HTTP in a gist
    130

    View Slide

  131. @another_clue
    HTTP in a gist
    131
    GET / HTTP/1.1

    View Slide

  132. @another_clue
    HTTP in a gist
    132
    GET / HTTP/1.1
    HTTP/1.1 200 OK
    Content-Type: text/plain
    hello world!

    View Slide

  133. @another_clue
    HTTP in a gist
    133
    GET / HTTP/1.1
    HTTP/1.1 200 OK
    Content-Type: text/plain
    hello world!

    View Slide

  134. @another_clue
    HTTP streaming
    134

    View Slide

  135. @another_clue
    HTTP streaming
    135
    - HTTP request/response semantics

    View Slide

  136. @another_clue
    HTTP streaming
    136
    - HTTP request/response semantics
    - streaming responses (download huge files)
    - streaming requests (upload huge files)

    View Slide

  137. @another_clue
    HTTP streaming
    137
    - HTTP request/response semantics
    - streaming responses (download huge files)
    - streaming requests (upload huge files)
    - Still request/response semantics

    View Slide

  138. @another_clue
    HTTP streaming
    138
    - HTTP request/response semantics
    - streaming responses (download huge files)
    - streaming requests (upload huge files)
    - Still request/response semantics
    - Long-polling (Comet) anyone?

    View Slide

  139. @another_clue
    HTTP streaming
    139
    - HTTP request/response semantics
    - streaming responses (download huge files)
    - streaming requests (upload huge files)
    - Still request/response semantics
    - Long-polling (Comet) anyone?

    View Slide

  140. @another_clue
    EventSource
    140

    View Slide

  141. @another_clue
    Server-Sent Events (SSE) / EventSource
    141

    View Slide

  142. @another_clue
    Server-Sent Events in a gist
    142
    - Normal Request/Response
    - Client API for streaming access

    View Slide

  143. @another_clue
    Server-Sent Events in a gist
    143
    - Normal Request/Response
    - Client API for streaming access
    HTTP/1.1 200 OK
    Content-Type: text/event-stream

    View Slide

  144. @another_clue
    Server-Sent Events in a gist
    144
    - Normal Request/Response
    - Client API for streaming access
    HTTP/1.1 200 OK
    Content-Type: text/event-stream
    data: hello

    View Slide

  145. @another_clue
    Server-Sent Events in a gist
    145
    - Normal Request/Response
    - Client API for streaming access
    HTTP/1.1 200 OK
    Content-Type: text/event-stream
    data: hello
    data: world

    View Slide

  146. @another_clue
    Server-Sent Events in a gist
    146
    - Normal Request/Response
    - Client API for streaming access
    HTTP/1.1 200 OK
    Content-Type: text/event-stream
    data: hello
    data: world

    View Slide

  147. @another_clue
    fully-functional streaming
    HTTP server in a single PHP
    file
    147

    View Slide

  148. @another_clue
    PubSub
    148

    View Slide

  149. @another_clue
    PubSub
    149
    - Publish/Subscribe

    View Slide

  150. @another_clue
    PubSub
    150
    - Publish/Subscribe
    - common pattern for distributed system

    View Slide

  151. @another_clue
    PubSub
    151
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between

    View Slide

  152. @another_clue
    PubSub
    152
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    Publisher Redis Subscriber

    View Slide

  153. @another_clue
    PubSub
    153
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    - horizontal scalability
    - independent components
    Publisher Redis Subscriber

    View Slide

  154. @another_clue
    PubSub
    154
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    - horizontal scalability
    - independent components
    Publisher Redis Subscriber
    Publisher Subscriber
    Publisher Subscriber

    View Slide

  155. @another_clue
    PubSub
    155
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    - horizontal scalability
    - independent components
    Publisher Redis Subscriber
    Publisher Subscriber
    Publisher Subscriber

    View Slide

  156. @another_clue
    PubSub
    156
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    - horizontal scalability
    - independent components
    Publisher Redis Subscriber
    Publisher Subscriber
    Publisher Subscriber

    View Slide

  157. @another_clue
    PubSub
    157
    - Publish/Subscribe
    - common pattern for distributed system
    - message broker in between
    - horizontal scalability
    - independent components
    Publisher Redis Subscriber
    Publisher Subscriber
    Publisher Subscriber

    View Slide

  158. @another_clue
    fully-functional, distributed
    HTTP streaming server in a
    single PHP file
    158

    View Slide

  159. @another_clue
    many, MANY more third-party projects:
    https://github.com/reactphp/react/wiki/Users
    159

    View Slide

  160. @another_clue
    Conclusions
    160

    View Slide

  161. @another_clue 161
    Can I use ReactPHP to make my website 1000x faster?

    View Slide

  162. @another_clue
    YES
    162
    Can I use ReactPHP to make my website 1000x faster?

    View Slide

  163. @another_clue
    YES
    163
    But you might be missing the point…
    Can I use ReactPHP to make my website 1000x faster?

    View Slide

  164. @another_clue
    PHP
    164

    View Slide

  165. @another_clue
    PHP
    faster than you probably thought
    165

    View Slide

  166. @another_clue
    PHP
    faster than you probably thought
    more versatile than you probably thought
    166

    View Slide

  167. @another_clue
    ReactPHP
    167

    View Slide

  168. @another_clue
    ReactPHP
    168
    a real deal and here to stay

    View Slide

  169. @another_clue
    ReactPHP
    169
    a real deal and here to stay
    stable & production ready

    View Slide

  170. @another_clue
    ReactPHP
    170
    a real deal and here to stay
    stable & production ready
    *awesome*

    View Slide

  171. @another_clue
    try!
    171

    View Slide

  172. @another_clue
    try!
    whenever having to wait
    172

    View Slide

  173. @another_clue
    try!
    whenever having to wait
    whenever accessing network
    173

    View Slide

  174. @another_clue
    help!
    174

    View Slide

  175. @another_clue
    help!
    elaborate documentation on ReactPHP.org
    175

    View Slide

  176. @another_clue
    help!
    elaborate documentation on ReactPHP.org
    tweet @ReactPHP or #reactphp
    176

    View Slide

  177. @another_clue
    help!
    elaborate documentation on ReactPHP.org
    tweet @ReactPHP or #reactphp
    Talk to me
    177

    View Slide

  178. @another_clue
    help!
    elaborate documentation on ReactPHP.org
    tweet @ReactPHP or #reactphp
    Talk to me
    Did I mention I’m available? 178

    View Slide

  179. @another_clue
    // thank you!
    $loop->stop();
    179
    @another_clue – https://clue.engineering/

    View Slide

  180. @another_clue
    integration
    180

    View Slide

  181. @another_clue
    integration
    non-blocking and blocking don’t mix well
    181

    View Slide

  182. @another_clue
    integration
    non-blocking and blocking don’t mix well
    decide for either approach
    182

    View Slide

  183. @another_clue
    integration
    non-blocking and blocking don’t mix well
    decide for either approach
    isolate & communicate
    183

    View Slide

  184. @another_clue
    Integration with traditional environments
    184
    integrating async into sync is easy

    View Slide

  185. @another_clue
    Integration with traditional environments
    185
    integrating async into sync is easy
    - just run the loop until you’re done
    - see clue/block-react

    View Slide

  186. @another_clue
    Integration with traditional environments
    186
    integrating async into sync is easy
    - just run the loop until you’re done
    - see clue/block-react
    integrating sync into async is hard

    View Slide

  187. @another_clue
    Integration with traditional environments
    187
    integrating async into sync is easy
    - just run the loop until you’re done
    - see clue/block-react
    integrating sync into async is hard
    - often requires async rewrite
    - consider forking instead

    View Slide

  188. @another_clue
    Avoid blocking!
    - The loop must not be blocked
    188

    View Slide

  189. @another_clue
    Avoid blocking!
    - The loop must not be blocked
    - Many functions / lib assume blocking by default
    - Anything >1ms should be reconsidered
    189

    View Slide

  190. @another_clue
    Avoid blocking!
    - The loop must not be blocked
    - Many functions / lib assume blocking by default
    - Anything >1ms should be reconsidered
    - Alternatives
    - Single result: Promises
    - Evented: Streams
    190

    View Slide

  191. @another_clue
    Avoid blocking!
    - The loop must not be blocked
    - Many functions / lib assume blocking by default
    - Anything >1ms should be reconsidered
    - Alternatives
    - Single result: Promises
    - Evented: Streams
    - Need a blocking function?
    - Fork off!
    - Use IPC
    191

    View Slide

  192. @another_clue
    Avoid blocking!
    - The loop must not be blocked
    - Many functions / lib assume blocking by default
    - Anything >1ms should be reconsidered
    - Alternatives
    - Single result: Promises
    - Evented: Streams
    - Need a blocking function?
    - Fork off!
    - Use IPC
    192
    Pay attention:
    - PDO, mysql etc.
    - file system access
    - network access
    - third-party APIs

    View Slide