万本电子书0元读

万本电子书0元读

顶部广告

JavaScript Concurrency电子书

售       价:¥

42人正在读 | 0人评论 9.8

作       者:Adam Boduch

出  版  社:Packt Publishing

出版时间:2015-12-29

字       数:153.8万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Build better software with concurrent JavaScript programming, and unlock a more efficient and forward thinking approach to web development About This Book Apply the core principles of concurrency to both browser and server side development Explore the latest tools and techniques at the forefront of concurrent programming, including JavaScript promises, web workers, and generators Learn how concurrent and parallel programming can help you tackle the challenges of fast, data heavy web development Who This Book Is For JavaScript Concurrency is written for any JavaScript developer who wants to learn how to write more efficient, powerful, and maintainable applications that utilize the latest developments in the JavaScript language. All aspects of concurrent, asynchronous, and parallel programming are covered from first principles and by the end of the book you’ll be able to create a fully-worked application that leverages all the topics covered in the book. What You Will Learn Understand exactly how JavaScript works in a web browser environment, and how these mechanisms power our event-driven JavaScript code Use promises to turn complex synchronization scenarios into readable and maintainable values Compute values lazily and avoid unnecessary memory allocations using generators. Write concurrent code that doesn’t feel like concurrent code by abstracting away boilerplate chores Leverage true hardware parallelism with web workers to get a better performance Get to grips with the NodeJS model of concurrency and learn why it’s good for I/O-intensive web applications In Detail 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. Style and approach Beginning with the fundamentals of concurrency and how they apply to JavaScript development, the book then takes you through the relevant constructs that will help you implement concurrent code. You’ll learn how even the most abstract and theoretical aspects of concurrent programming help you solve real world challenges, with clear and practical demonstrations that show you how concurrent JavaScript will make you a better developer.
目录展开

JavaScript Concurrency

Table of Contents

JavaScript Concurrency

Credits

About the Author

About the Reviewer

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Why JavaScript Concurrency?

Synchronous JavaScript

Synchronicity is easy to understand

Asynchronous is inevitable

Asynchronous browsers

Types of concurrency

Asynchronous actions

Parallel actions

JavaScript concurrency principles: Parallelize, Synchronize, Conserve

Parallelize

Synchronize

The Promise API

Conserve

Summary

2. The JavaScript Execution Model

Everything is a task

Meet the players

The Execution environment

Event loops

Task queues

Execution contexts

Maintaining execution state

Job queues

Creating tasks using timers

Using setTimeout()

Using setInterval()

Responding to DOM events

Event targets

Managing event frequency

Responding to network events

Making requests

Coordinating requests

Concurrency challenges with this model

Limited opportunity for parallelism

Synchronization through callbacks

Summary

3. Synchronizing with Promises

Promise terminology

Promise

State

Executor

Resolver

Rejector

Thenable

Resolving and rejecting promises

Resolving promises

Rejecting promises

Empty promises

Reacting to promises

Resolution job queues

Using promised data

Error callbacks

Always reacting

Resolving other promises

Promise–like objects

Building callback chains

Promises only change state once

Immutable promises

Many then callbacks, many promises

Passing promises around

Synchronizing several promises

Waiting on promises

Cancelling promises

Promises without executors

Summary

4. Lazy Evaluation with Generators

Call stacks and memory allocation

Bookmarking function contexts

Sequences instead of arrays

Creating generators and yielding values

Generator function syntax

Yielding values

Iterating over generators

Infinite sequences

No end in sight

Alternating sequences

Deferring to other generators

Selecting a strategy

Interweaving generators

Passing data to generators

Reusing generators

Lightweight map/reduce

Coroutines

Creating coroutine functions

Handling DOM events

Handling promised values

Summary

5. Working with Workers

What are workers?

OS threads

Event targets

True parallelism

Types of workers

Dedicated workers

Sub-workers

Shared workers

Worker environments

What's available, what isn't?

Loading scripts

Communicating with workers

Posting messages

Message serialization

Receiving messages from workers

Sharing application state

Sharing memory

Fetching resources

Communicating between pages

Performing sub-tasks with sub-workers

Dividing work into tasks

A word of caution

Error handling in web workers

Error condition checking

Exception handling

Summary

6. Practical Parallelism

Functional programming

Data in, data out

Immutability

Referential transparency and time

Do we need to go parallel?

How big is the data?

Hardware concurrency capabilities

Creating tasks and assigning work

Candidate problems

Embarrassingly parallel

Searching collections

Mapping and reducing

Keeping the DOM responsive

Bottom halves

Translating DOM manipulation

Translating DOM events

Summary

7. Abstracting Concurrency

Writing concurrent code

Hiding the concurrency mechanism

Without concurrency

Worker communication with promises

Helper functions

Extending postMessage()

Synchronizing worker results

Lazy workers

Reducing overhead

Generating values in workers

Lazy worker chains

Using Parallel.js

How it works

Spawning workers

Mapping and reducing

Worker pools

Allocating pools

Scheduling jobs

Summary

8. Evented IO with NodeJS

Single threaded IO

IO is slow

IO events

Multi-threading challenges

More connections, more problems

Deploying to the Internet

The C10K problem

Lightweight event handlers

Evented network IO

Handling HTTP requests

Streaming responses

Proxy network requests

Evented file IO

Reading from files

Writing to files

Streaming reads and writes

Summary

9. Advanced NodeJS Concurrency

Coroutines with Co

Generating promises

Awaiting values

Resolving values

Asynchronous dependencies

Wrapping coroutines

Child Processes

Blocking the event loop

Forking processes

Spawning external processes

Inter-process communication

Process Clusters

Challenges with process management

Abstracting process pools

Server clusters

Proxying requests

Facilitating micro-services

Informed load balancing

Summary

10. Building a Concurrent Application

Getting started

Concurrency first

Retrofitting concurrency

Application types

Requirements

The overall goal

The API

The UI

Building the API

The HTTP server and routing

Co-routines as handlers

The create chat handler

The join chat handler

The load chat handler

The send message handler.

Static handlers

Building the UI

Talking to the API

Implementing the HTML

DOM events and manipulation

Adding an API worker

Additions and improvements

Clustering the API

Cleaning up chats

Asynchronous entry points

Who's typing?

Leaving chats

Polling timeouts

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部