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

Off the main thread with workers !

Off the main thread with workers !

This is a presentation slide I presented at Node学園 in Tokyo on April 27th, 2018

Mariko Kosaka

April 27, 2018
Tweet

More Decks by Mariko Kosaka

Other Decks in Technology

Transcript

  1. const pattern =/(\d{4})-(\d{2})-(\d{2})/u; const result = pattern.exec(‘2018-03-06'); // ! result[0]

    === '2018-03-06' // ! result[1] === '2018' // ! result[2] === '03' // ! result[3] === '06'
  2. // Rest properties for object destructuring assignment: const person =

    { firstName:’Sebastian', lastName:’Markbåge', country:'USA', state:’CA'}; const{ firstName, lastName, ...rest } = person; console.log(firstName); // Sebastian console.log(lastName); // Markbåge console.log(rest); // { country: 'USA', state: 'CA' }
  3. // Spread properties for object literals: const personCopy ={ firstName,

    lastName, ...rest }; console.log(personCopy); // { firstName: 'Sebastian', // lastName: 'Markbåge', // country: 'USA', // state: 'CA' }
  4. const worker = new Worker('worker.js'); worker.postMessage(data); worker.onmessage = (message) =>

    { // do something on main thread }; self.onmessage = (message) => { // do something high cost self.postMessage(data) }
  5. importScripts('vp10decode.js', 'mp4encode.js'); const transcoder = new TransformStream({ transform(chunk, controller) {

    const decoded = vp10decode(chunk); controller.enqueue(mp4encode(decoded)); } }); postMessage(transcoder, [transcoder]); const worker = new Worker('transcode.js'); worker.onmessage = event => { const transcoder = event.data; await fetch('bunny.vp10') .pipeThrough(transcoder) .pipeTo(videoSink); };