SlideShare ist ein Scribd-Unternehmen logo
1 von 16
An Introduction to WebWorker
  by Leo Tse
Agenda

1. Javascript – the event driven language
2. Limitations
3. Web Worker
4. Browser Support
5. Q & A
How does the browser execute
Javascript?
› Javascript is event-driven
› 3 main ways scripts get executed
   › <script></script>
   › Internal events (page load, setTimeout, etc)
   › User input (click, focus, etc)
› When one of these occurs, the event gets
  added to the event queue
The Event Loop


› The Javascript event loop looks at the
  event queue periodically
› Executes event handlers/callbacks when
  the queue is not empty
The event loop postman!




         Source: http://developer.yahoo.com/blogs/ydn/posts/2010/10/understanding-
         the-event-loops-and-writing-great-code-for-node-js-part-1/
Source: http://developer.yahoo.com/blogs/ydn/posts/2010/10/understanding-
the-event-loops-and-writing-great-code-for-node-js-part-1/
Limitations
› Javascript is single threaded
   › It can only do one thing at a time
› Most browser uses a single event queue
  for Javascript and UI rendering
   › While Javascript is running, no rendering
      occurs
  ›   Page becomes unresponsive
Web Worker

› Definition - “An API that allows Web
 application authors to spawn background
 workers running scripts in parallel to their
 main page. This allows for thread-like
 operation with message-passing as the
 coordination mechanism"
Demo Logic Flow
             Main Page                                           Worker




Initialize               worker.postMessage({‘cmd’ : ‘start’})        Start
worker                                                                loop



Show output                 self.postMessage(100000000)               Counter reached
100000000                                                             100000000

Show output                 self.postMessage(200000000)               Counter reached
200000000                                                             200000000

Show output                self.postMessage(300000000)                Counter reached
300000000                                                             300000000
Worker Features
› Web workers only has access to a subset of JavaScript's
  features
   › The navigator object
   › The location object (read-only)
   › XMLHttpRequest
   › setTimeout()/clearTimeout() and
     setInterval()/clearInterval()
   › Importing external scripts using the importScripts()
     method
   › Spawning other web workers
› In summary, you can’t modify the UI
Stopping a worker


› 2 ways to stop a worker
   › Worker.terminate() in parent page
   › close() in worker
› Once the worker is stopped, it has to be re-initialized
Error Handling



› worker.addEventListener("error", callback)
   › filename, lineno, message properties are available for
     debugging
Worker use cases


›   Prefetching data
›   Background polling
›   Parsing big xml/json
›   Image processing
›   Any CPU intensive tasks
Browser Support




              Source: http://caniuse.com/webworkers
Questions?


› Slides will be posted to SlideShare
 We will send out the link later

› You can email me at:
 leo.tse@digiflare.com
Thanks!

Weitere ähnliche Inhalte

Was ist angesagt?

Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps runFrederik De Bruyne
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! GrailsプラグインTsuyoshi Yamamoto
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interfaceJoakim Gustin
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」Tsuyoshi Yamamoto
 
An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to JqueryPhil Reither
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript CodeSuresh Balla
 
Ciclo di vita di una applicazione windows phone tips & tricks
Ciclo di vita di una applicazione windows phone tips & tricksCiclo di vita di una applicazione windows phone tips & tricks
Ciclo di vita di una applicazione windows phone tips & tricksDan Ardelean
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwiftScott Gardner
 
Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+Bryan Hughes
 
Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018Lara Schenck
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftAaron Douglas
 
«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»Olga Lavrentieva
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)Shivani Thakur Daxini
 

Was ist angesagt? (18)

Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run
 
Class ‘increment’
Class ‘increment’Class ‘increment’
Class ‘increment’
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
第3回Grails/Groovy勉強会名古屋「Grails名古屋座談会」
 
An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to Jquery
 
Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript Code
 
Ciclo di vita di una applicazione windows phone tips & tricks
Ciclo di vita di una applicazione windows phone tips & tricksCiclo di vita di una applicazione windows phone tips & tricks
Ciclo di vita di una applicazione windows phone tips & tricks
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
 
Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+Understanding Functions and "this" in the World of ES2017+
Understanding Functions and "this" in the World of ES2017+
 
Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018Let's Build A Gutenberg Block | WordCamp Europe 2018
Let's Build A Gutenberg Block | WordCamp Europe 2018
 
Alt.Net Presentation
Alt.Net PresentationAlt.Net Presentation
Alt.Net Presentation
 
Oo
OoOo
Oo
 
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwiftSwift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
Swift & ReactiveX – Asynchronous Event-Based Funsies with RxSwift
 
«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»«Работа с базами данных с использованием Sequel»
«Работа с базами данных с использованием Sequel»
 
Window object methods (timer related)
Window object methods (timer related)Window object methods (timer related)
Window object methods (timer related)
 

Andere mochten auch

NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
 
Introduce native client
Introduce native clientIntroduce native client
Introduce native clientYoung-Ho Cha
 
Bringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersBringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersCorey Clark, Ph.D.
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJSDicoding
 
Total Synthesis of (+)-Perophoramidine
Total Synthesis of (+)-PerophoramidineTotal Synthesis of (+)-Perophoramidine
Total Synthesis of (+)-PerophoramidineMuhammad Ehsan
 
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...Yoga Tokuyoshi
 
060812 EEOC Response (VIETNAMESE)
060812   EEOC Response (VIETNAMESE)060812   EEOC Response (VIETNAMESE)
060812 EEOC Response (VIETNAMESE)VogelDenise
 
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)VogelDenise
 
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)VogelDenise
 
102912 vogel denise slideshare documents (bengali)
102912   vogel denise slideshare documents (bengali)102912   vogel denise slideshare documents (bengali)
102912 vogel denise slideshare documents (bengali)VogelDenise
 
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)VogelDenise
 
OpenNebula Project - FOSDEM 2012
OpenNebula Project - FOSDEM 2012OpenNebula Project - FOSDEM 2012
OpenNebula Project - FOSDEM 2012dmamolina
 
Nuremberg principle georgian
Nuremberg principle   georgianNuremberg principle   georgian
Nuremberg principle georgianVogelDenise
 
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...VogelDenise
 
122912 public notification (obama & pay pal attacks) - catalan
122912   public notification (obama & pay pal attacks) - catalan122912   public notification (obama & pay pal attacks) - catalan
122912 public notification (obama & pay pal attacks) - catalanVogelDenise
 
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16VogelDenise
 
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)VogelDenise
 
102912 vogel denise slideshare documents (german)
102912   vogel denise slideshare documents (german)102912   vogel denise slideshare documents (german)
102912 vogel denise slideshare documents (german)VogelDenise
 
060812 EEOC Response (FINNISH)
060812   EEOC Response (FINNISH)060812   EEOC Response (FINNISH)
060812 EEOC Response (FINNISH)VogelDenise
 

Andere mochten auch (20)

NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Introduce native client
Introduce native clientIntroduce native client
Introduce native client
 
Bringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersBringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkers
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
 
Total Synthesis of (+)-Perophoramidine
Total Synthesis of (+)-PerophoramidineTotal Synthesis of (+)-Perophoramidine
Total Synthesis of (+)-Perophoramidine
 
Qq
QqQq
Qq
 
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...
■国際心理学会ICP2016 クリエイティブ・フロー(創造的なフロー尺度)の開発。創造性のスキルと自己効力感(自信) Development and va...
 
060812 EEOC Response (VIETNAMESE)
060812   EEOC Response (VIETNAMESE)060812   EEOC Response (VIETNAMESE)
060812 EEOC Response (VIETNAMESE)
 
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Basque)
 
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)
052215 - FAX TO DELNER THOMAS & BENNIE THOMPSON (Estonian)
 
102912 vogel denise slideshare documents (bengali)
102912   vogel denise slideshare documents (bengali)102912   vogel denise slideshare documents (bengali)
102912 vogel denise slideshare documents (bengali)
 
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)
BAKER DONELSON - Attorney Layoffs The SINKING OF A TERRORIST REGIME (BASQUE)
 
OpenNebula Project - FOSDEM 2012
OpenNebula Project - FOSDEM 2012OpenNebula Project - FOSDEM 2012
OpenNebula Project - FOSDEM 2012
 
Nuremberg principle georgian
Nuremberg principle   georgianNuremberg principle   georgian
Nuremberg principle georgian
 
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...
2016 The YEAR Of OVERTHROW And WE THE PEOPLE LEGALLY & LAWFULLY TAKING BACK C...
 
122912 public notification (obama & pay pal attacks) - catalan
122912   public notification (obama & pay pal attacks) - catalan122912   public notification (obama & pay pal attacks) - catalan
122912 public notification (obama & pay pal attacks) - catalan
 
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16
LIST OF AMERICAN JEWISH POLITICIANS - WIKIPEDIA As Of 07/17/16
 
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)
2016 FAMU SPORTS HALL OF FAME INDUCTEES (Vogel Newsome)
 
102912 vogel denise slideshare documents (german)
102912   vogel denise slideshare documents (german)102912   vogel denise slideshare documents (german)
102912 vogel denise slideshare documents (german)
 
060812 EEOC Response (FINNISH)
060812   EEOC Response (FINNISH)060812   EEOC Response (FINNISH)
060812 EEOC Response (FINNISH)
 

Ähnlich wie An Introduction to WebWorker - 01.26.12

Web workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIWeb workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIpcnmtutorials
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsMike Hagedorn
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
Client Side rendering Not so Easy
Client Side rendering Not so EasyClient Side rendering Not so Easy
Client Side rendering Not so Easynuria_ruiz
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
Revealing Unique MitB Builder C&C Server
Revealing Unique MitB Builder C&C ServerRevealing Unique MitB Builder C&C Server
Revealing Unique MitB Builder C&C ServerSenad Aruc
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message BrokersPROIDEA
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Alessandro Molina
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介dena_genom
 
Implementações paralelas
Implementações paralelasImplementações paralelas
Implementações paralelasWillian Molinari
 
FRP: What does "declarative" mean
FRP: What does "declarative" meanFRP: What does "declarative" mean
FRP: What does "declarative" meanPeter Ovchinnikov
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 

Ähnlich wie An Introduction to WebWorker - 01.26.12 (20)

Web workers | JavaScript | HTML API
Web workers | JavaScript | HTML APIWeb workers | JavaScript | HTML API
Web workers | JavaScript | HTML API
 
Responsive interfaces
Responsive interfacesResponsive interfaces
Responsive interfaces
 
Playing With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.jsPlaying With Fire - An Introduction to Node.js
Playing With Fire - An Introduction to Node.js
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Client Side rendering Not so Easy
Client Side rendering Not so EasyClient Side rendering Not so Easy
Client Side rendering Not so Easy
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
(18.03.2009) Cumuy Invita - Iniciando el año conociendo nuevas tecnologías - ...
(18.03.2009) Cumuy Invita - Iniciando el año conociendo nuevas tecnologías - ...(18.03.2009) Cumuy Invita - Iniciando el año conociendo nuevas tecnologías - ...
(18.03.2009) Cumuy Invita - Iniciando el año conociendo nuevas tecnologías - ...
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Revealing Unique MitB Builder C&C Server
Revealing Unique MitB Builder C&C ServerRevealing Unique MitB Builder C&C Server
Revealing Unique MitB Builder C&C Server
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
 
Developing Async Sense
Developing Async SenseDeveloping Async Sense
Developing Async Sense
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介
 
Implementações paralelas
Implementações paralelasImplementações paralelas
Implementações paralelas
 
Workers
WorkersWorkers
Workers
 
FRP: What does "declarative" mean
FRP: What does "declarative" meanFRP: What does "declarative" mean
FRP: What does "declarative" mean
 
Writing a slack chatbot mxlos
Writing a slack chatbot mxlosWriting a slack chatbot mxlos
Writing a slack chatbot mxlos
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 

Kürzlich hochgeladen

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Kürzlich hochgeladen (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

An Introduction to WebWorker - 01.26.12

  • 1. An Introduction to WebWorker by Leo Tse
  • 2. Agenda 1. Javascript – the event driven language 2. Limitations 3. Web Worker 4. Browser Support 5. Q & A
  • 3. How does the browser execute Javascript? › Javascript is event-driven › 3 main ways scripts get executed › <script></script> › Internal events (page load, setTimeout, etc) › User input (click, focus, etc) › When one of these occurs, the event gets added to the event queue
  • 4. The Event Loop › The Javascript event loop looks at the event queue periodically › Executes event handlers/callbacks when the queue is not empty
  • 5. The event loop postman! Source: http://developer.yahoo.com/blogs/ydn/posts/2010/10/understanding- the-event-loops-and-writing-great-code-for-node-js-part-1/
  • 7. Limitations › Javascript is single threaded › It can only do one thing at a time › Most browser uses a single event queue for Javascript and UI rendering › While Javascript is running, no rendering occurs › Page becomes unresponsive
  • 8. Web Worker › Definition - “An API that allows Web application authors to spawn background workers running scripts in parallel to their main page. This allows for thread-like operation with message-passing as the coordination mechanism"
  • 9. Demo Logic Flow Main Page Worker Initialize worker.postMessage({‘cmd’ : ‘start’}) Start worker loop Show output self.postMessage(100000000) Counter reached 100000000 100000000 Show output self.postMessage(200000000) Counter reached 200000000 200000000 Show output self.postMessage(300000000) Counter reached 300000000 300000000
  • 10. Worker Features › Web workers only has access to a subset of JavaScript's features › The navigator object › The location object (read-only) › XMLHttpRequest › setTimeout()/clearTimeout() and setInterval()/clearInterval() › Importing external scripts using the importScripts() method › Spawning other web workers › In summary, you can’t modify the UI
  • 11. Stopping a worker › 2 ways to stop a worker › Worker.terminate() in parent page › close() in worker › Once the worker is stopped, it has to be re-initialized
  • 12. Error Handling › worker.addEventListener("error", callback) › filename, lineno, message properties are available for debugging
  • 13. Worker use cases › Prefetching data › Background polling › Parsing big xml/json › Image processing › Any CPU intensive tasks
  • 14. Browser Support Source: http://caniuse.com/webworkers
  • 15. Questions? › Slides will be posted to SlideShare We will send out the link later › You can email me at: leo.tse@digiflare.com