Preface
Chapter 1: Why JavaScript Concurrency?Synchronous JavaScriptSynchronicity is easy to understandAsynchronous is inevitableAsynchronous browsersTypes of concurrencyAsynchronous actionsParallel actionsJavaScript concurrency principles: Parallelize, Synchronize,ConserveParallelizeSynchronizeThe Promise APIConserveSummary
Chapter 2: The JavaScript Execution ModelEverything is a taskMeet the playersThe Execution environmentEvent loopsTask queuesExecution contextsMaintaining execution stateJob queuesCreating tasks using timersUsing setTimeout()Using setlnterval()Responding to DOM eventsEvent targetsManaging event frequencyResponding to network eventsMaking requestsCoordinating requestsConcurrency challenges with this modelLimited opportunity for parallelismSynchronization through callbacksSummary
Chapter 3: Synchronizing with PromisesPromise terminologyPromiseStateExecutorResolverRejectorThenableResolving and rejecting promisesResolving promisesRejecting promisesEmpty promisesReacting to promisesResolution job queuesUsing promised dataError callbacksAlways reactingResolving other promisesPromise-like objectsBuilding callback chainsPromises only change state onceImmutable promisesMany then callbacks, many promisesPassing promises aroundSynchronizing several promisesWaiting on promisesCancelling promisesPromises without executorsSummary
Chapter 4: Lazy Evaluation with GeneratorsCall stacks and memory allocationBookmarking function contextsSequences instead of arraysCreating generators and yielding valuesGenerator function syntaxYielding valuesIterating over generatorsInfinite sequencesNo end in sightAlternating sequencesDeferring to other generatorsSelecting a strategyInterweaving generatorsPassing data to generatorsReusing generatorsLightweight map/reduceCoroutinesCreating coroutine functionsHandling DOM eventsHandling promised valuesSummary
Chapter 5: Working with WorkersWhat are workers?OS threadsEvent targetsTrue parallelismTypes of workersDedicated workersSub-workersShared workersWorker environmentsWhat's available, what isn't?Loading scriptsCommunicating with workersPosting messagesMessage serializationReceiving messages from workersSharing application stateSharing memoryFetching resourcesCommunicating between pagesPerforming sub-tasks with sub-workersDividing work into tasksA word of cautionError handling in web workersError condition checkingException handlingSummary
Chapter 6: Practical ParallelismFunctional programmingData in, data outImmutabilityReferential transparency and timeDo we need to go parallel?How big is the data?Hardware concurrency capabilitiesCreating tasks and assigning workCandidate problemsEmbarrassingly parallelSearching collectionsMapping and reducingKeeping the DOM responsiveBottom halvesTranslating DOM manipulationTranslating DOM eventsSummary
Chapter 7: Abstracting ConcurrencyWriting concurrent codeHiding the concurrency mechanismWithout concurrencyWorker communication with promisesHelper functionsExtending postMessage0Synchronizing worker resultsLazy workersReducing overheadGenerating values in workersLazy worker chainsUsing Parallel.jsHow it worksSpawning workersMapping and reducingWorker poolsAllocating poolsScheduling jobsSummary
Chapter 8: Evented IO with NodeJSSingle threaded IOIO is slowIO eventsMulti-threading challengesMore connections, more problemsDeploying to the InternetThe C10K problemLightweight event handlersEvented network IOHandling HTTP requestsStreaming responsesProxy network requestsEvented file IOReading from filesWriting to filesStreaming reads and writesSummary
Chapter 9: Advanced NodeJS ConcurrencyCoroutines with CoGenerating promisesAwaiting valuesResolving valuesAsynchronous dependenciesWrapping coroutinesChild ProcessesBlocking the event loopForking processesSpawning external processesInter-process communicationProcess ClustersChallenges with process managementAbstracting process poolsServer clustersProxying requestsFacilitating micro-servicesInformed load balancingSummary
Chapter 10: Building a Concurrent ApplicationGetting startedConcurrency firstRetrofitting concurrencyApplication typesRequirementsThe overall goalThe APIThe UIBuilding the APIThe HTTP server and routingCo-routines as handlersThe create chat handlerThe join chat handlerThe load chat handlerThe send message handler.Static handlersBuilding the UITalking to the APIImplementing the HTMLDOM events and manipulationAdding an API workerAdditions and improvementsClustering the APICleaning up chatsAsynchronous entry pointsWho's typing?Leaving chatsPolling timeoutsSummary
Index