Book Image

JavaScript Concurrency

By : Adam Boduch
Book Image

JavaScript Concurrency

By: Adam Boduch

Overview of this book

Concurrent programming may sound abstract and complex, but it helps to deliver a better user experience. With single threaded JavaScript, applications lack dynamism. This means that when JavaScript code is running, nothing else can happen. The DOM can’t update, which means the UI freezes. In a world where users expect speed and responsiveness – in all senses of the word – this is something no developer can afford. Fortunately, JavaScript has evolved to adopt concurrent capabilities – one of the reasons why it is still at the forefront of modern web development. This book helps you dive into concurrent JavaScript, and demonstrates how to apply its core principles and key techniques and tools to a range of complex development challenges. Built around the three core principles of concurrency – parallelism, synchronization, and conservation – you’ll learn everything you need to unlock a more efficient and dynamic JavaScript, to lay the foundations of even better user experiences. Throughout the book you’ll learn how to put these principles into action by using a range of development approaches. Covering everything from JavaScript promises, web workers, generators and functional programming techniques, everything you learn will have a real impact on the performance of your applications. You’ll also learn how to move between client and server, for a more frictionless and fully realized approach to development. With further guidance on concurrent programming with Node.js, JavaScript Concurrency is committed to making you a better web developer. The best developers know that great design is about more than the UI – with concurrency, you can be confident every your project will be expertly designed to guarantee its dynamism and power.
Table of Contents (17 chapters)
JavaScript Concurrency
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Index

A

  • API
    • building / Building the API
  • API communication / Talking to the API
  • API worker
    • adding / Adding an API worker
  • applications
    • deploying, to Internet / Deploying to the Internet
  • application state
    • sharing / Sharing application state
  • application types
    • about / Application types
  • array
    • using / Sequences instead of arrays
    • iterating over / Sequences instead of arrays
  • asynchronous browsers
    • about / Asynchronous browsers
  • asynchronous JavaScript
    • about / Asynchronous is inevitable

B

  • bottom-halves
    • about / Bottom halves

C

  • C10K problem
    • about / The C10K problem
    • reference link / The C10K problem
  • callback chains
    • building / Building callback chains
  • call stacks
    • about / Call stacks and memory allocation
  • co-routines
    • using, as handlers / Co-routines as handlers
  • communicating, with workers
    • about / Communicating with workers
    • messages, posting / Posting messages
    • message serialization / Message serialization
    • messages, receiving from workers / Receiving messages from workers
  • concurrency
    • about / Concurrency first
    • retrofitting / Retrofitting concurrency
  • concurrency challenges, execution model
    • about / Concurrency challenges with this model
    • limited opportunity for parallelism / Limited opportunity for parallelism
    • synchronization through callbacks / Synchronization through callbacks
  • concurrency mechanism
    • hiding / Hiding the concurrency mechanism
  • concurrency principles, JavaScript
    • about / JavaScript concurrency principles: Parallelize, Synchronize, Conserve
    • parallelize / Parallelize
    • synchronize / Synchronize
    • conserve / Conserve
  • concurrency technique
    • downsides / A word of caution
  • concurrent actions, JavaScript code
    • about / Types of concurrency
    • asynchronous actions / Asynchronous actions
    • parallel actions / Parallel actions
  • concurrent application, requisites
    • about / Requirements
    • overall goal / The overall goal
    • API / The API
    • UI / The UI
  • concurrent code
    • writing / Writing concurrent code
  • concurrent programming
    • about / Synchronicity is easy to understand, Writing concurrent code
  • conserve principle, JavaScript
    • about / Conserve
    • checklist / Conserve
  • coroutine functions
    • creating / Creating coroutine functions
  • coroutines
    • about / Coroutines
    • functions, creating / Creating coroutine functions
    • DOM events, handling / Handling DOM events
    • promised values, handling / Handling promised values
  • create chat handler / The create chat handler

D

  • data
    • passing, to generators / Passing data to generators
  • debouncing
    • about / Responding to DOM events
  • dedicated workers
    • about / Dedicated workers
  • Document Object Model (DOM)
    • about / Synchronous JavaScript
  • DOM events
    • responding to / Responding to DOM events
    • handling / Handling DOM events
    • translating / Translating DOM events
    • about / DOM events and manipulation
  • DOM manipulation
    • translating / Translating DOM manipulation
    / DOM events and manipulation
  • DOM responsive, for users
    • bottom halves / Bottom halves

E

  • empty promises
    • about / Empty promises
  • error callbacks / Error callbacks
  • error handling, in web workers
    • about / Error handling in web workers
    • error condition checking / Error condition checking
    • exception handling / Exception handling
  • evented file IO
    • about / Evented file IO
  • evented network IO
    • about / Evented network IO
    • HTTP requests, handling / Handling HTTP requests
    • HTTP response, streaming / Streaming responses
  • event frequency
    • managing / Managing event frequency
  • event loop
    • about / Meet the players, Event loops
  • EventTarget interface
    • about / Event targets
  • execution contexts
    • about / Execution contexts
  • execution environment
    • about / Meet the players, The Execution environment
  • execution state
    • maintaining / Maintaining execution state
  • executor
    • about / Executor

F

  • file reads
    • streaming / Streaming reads and writes
  • files
    • reading from / Reading from files
    • writing to / Writing to files
  • file writes
    • streaming / Streaming reads and writes
  • first in first out (FIFO) / Bottom halves
  • function contexts
    • bookmarking / Bookmarking function contexts

G

  • generator
    • lightweight map/reduce, performing / Lightweight map/reduce
  • generators
    • values, yielding / Creating generators and yielding values, Yielding values
    • creating / Creating generators and yielding values
    • function syntax / Generator function syntax
    • iterating over / Iterating over generators
    • interweaving / Interweaving generators
    • data, passing to / Passing data to generators
    • reusing / Reusing generators
  • genMap() function / Lightweight map/reduce

H

  • handlers
    • co-routines, using as / Co-routines as handlers
  • HTTP requests
    • handling / Handling HTTP requests
  • HTTP response
    • streaming / Streaming responses
  • HTTP server
    • about / The HTTP server and routing

I

  • immutable promises
    • about / Immutable promises
  • improvements
    • about / Additions and improvements
    • API, clustering / Clustering the API
    • chats, cleaning up / Cleaning up chats
    • asynchronous entry points / Asynchronous entry points
    • typing state / Who's typing?
    • chats, leaving / Leaving chats
    • timeouts, polling / Polling timeouts
  • infinite sequences
    • about / Infinite sequences
    • items, allocating / No end in sight
    • alternating / Alternating sequences
  • informed load balancing / Informed load balancing
  • Internet
    • applications, deploying to / Deploying to the Internet
  • IO events
    • about / IO events
  • IO loop / Single threaded IO
  • iteratee function / Lightweight map/reduce

J

  • JavaScript
    • concurrency principles / JavaScript concurrency principles: Parallelize, Synchronize, Conserve
  • JavaScript application
    • writing, without concurrency / Without concurrency
  • JavaScript code
    • concurrent actions / Types of concurrency
  • JavaScript interpreter
    • about / Meet the players
  • job queues
    • about / Job queues
  • join chat handler / The join chat handler

L

  • lazy worker chains
    • about / Lazy worker chains
  • lazy workers
    • about / Lazy workers
    • overhead, reducing / Reducing overhead
  • lightweight event handlers
    • about / Lightweight event handlers
  • load chat handler / The load chat handler

M

  • memory allocation
    • about / Call stacks and memory allocation
  • mesh of generators
    • creating / Deferring to other generators
  • messages
    • receiving, from workers / Receiving messages from workers
  • multi-threading
    • challenges / Multi-threading challenges
  • multi-threading environments
    • about / Synchronicity is easy to understand
  • multiple connections
    • challenges / More connections, more problems

N

  • next() method / Lightweight map/reduce
  • node-http-proxy
    • reference link / Facilitating micro-services

P

  • Parallel.js
    • using / Using Parallel.js
    • working / How it works
    • workers, spawning / Spawning workers
    • mapping / Mapping and reducing
    • reducing / Mapping and reducing
  • parallelize principle, JavaScript
    • about / Parallelize
    • checklist / Parallelize
  • parallel slowdown / Mapping and reducing
  • pools
    • allocating, of worker threads / Allocating pools
  • promise
    • about / Promise
    • rejecting / Resolving and rejecting promises, Rejecting promises
    • resolving / Resolving promises, Resolving other promises
    • reacting to / Reacting to promises, Always reacting
    • state, changing / Promises only change state once
    • passing, around / Passing promises around
    • waiting on / Waiting on promises
    • cancelling / Cancelling promises
    • without executors / Promises without executors
  • promise, states
    • pending / State
    • fulfilled / State
    • rejected / State
  • Promise.resolve() method / Promise–like objects
  • Promise API
    • about / The Promise API
  • promise chain example / Many then callbacks, many promises
  • promised data
    • using / Using promised data
  • promised values
    • handling / Handling promised values
  • promise terminology
    • about / Promise terminology
    • promise / Promise
    • state / State
    • executor / Executor
    • resolver / Resolver
    • rejector / Rejector
    • thenable / Thenable
  • proxy network requests
    • about / Proxy network requests

R

  • rejector
    • about / Rejector
  • request routing mechanisms
    • about / The HTTP server and routing
  • resolution job queues / Resolution job queues
  • resolver
    • about / Resolver
  • responding, to network events
    • about / Responding to network events
    • requests, making / Making requests
    • requests, coordinating / Coordinating requests
  • run-to-completion (RTC)
    • about / Synchronous JavaScript

S

  • send message handler / The send message handler.
  • sequences
    • about / Sequences instead of arrays
    • iterating over / Sequences instead of arrays
    • infinite sequences / Infinite sequences
  • server clusters
    • micro-services, facilitating / Facilitating micro-services
    • informed load balancing / Informed load balancing
  • setInterval() function
    • using / Using setInterval()
  • setTimeout() function
    • using / Using setTimeout()
  • several promises
    • synchronizing / Synchronizing several promises
  • shared workers
    • about / Shared workers
  • single threaded IO
    • about / Single threaded IO
    • slow IO / IO is slow
    • IO events / IO events
  • static handlers / Static handlers
  • strategy
    • selecting / Selecting a strategy
  • subtasks
    • performing, with subworkers / Performing sub-tasks with sub-workers
  • subworkers
    • subtasks, performing with / Performing sub-tasks with sub-workers
    • about / A word of caution
  • sub workers
    • about / Sub-workers
  • synchronize principle, JavaScript
    • about / Synchronize
    • checklist / The Promise API
  • synchronous JavaScript
    • about / Synchronous JavaScript
    • easy to understand / Synchronicity is easy to understand

T

  • task queue
    • about / Meet the players
  • task queues
    • about / Task queues
  • tasks
    • creating, timers used / Creating tasks using timers
    • work, dividing into / Dividing work into tasks
  • thenable
    • about / Thenable
  • thread
    • about / Synchronicity is easy to understand
  • timers
    • used, for creating tasks / Creating tasks using timers

U

  • UI
    • building / Building the UI
    • HTML, implementing / Implementing the HTML

V

  • values
    • yielding, to generator / Creating generators and yielding values, Yielding values
    • generating, in workers / Generating values in workers

W

  • web worker execution environments
    • reference link / What's available, what isn't?
  • web workers
    • memory, sharing / Sharing memory
    • resources, fetching / Fetching resources
    • communicating, between pages / Communicating between pages
  • work
    • dividing, into tasks / Dividing work into tasks
  • worker communication, with promises
    • about / Worker communication with promises
    • helper functions / Helper functions
    • postMessage(), extending / Extending postMessage()
    • worker results, synchronizing / Synchronizing worker results
  • worker environments
    • about / Worker environments
    • scripts, loading / Loading scripts
  • worker pools
    • about / Worker pools
    • jobs, scheduling / Scheduling jobs
  • workers
    • about / What are workers?
    • OS threads / OS threads
    • event targets / Event targets
    • true parallelism / True parallelism
    • messages, receiving from / Receiving messages from workers
    • values, generating in / Generating values in workers
  • workers, types
    • about / Types of workers
    • dedicated workers / Dedicated workers
    • sub workers / Sub-workers
    • shared workers / Shared workers
  • worker threads
    • pools, allocating of / Allocating pools
  • World Wide Web Consortium (W3C)
    • about / Everything is a task

X

  • XMLHttpRequest (XHR)
    • about / Synchronous JavaScript