Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
JavaScript

JavaScript: Web Workers ile Parallel Processing

- 18.08.26 - ErcanOPAK

🧵 Web Workers = Parallel Processing

Single thread yeterli değil. Web Workers ile background processing yapın.

🎯 Web Worker Implementation

// 1. Worker File (worker.js)
self.addEventListener('message', (e) => {
    const data = e.data;
    const result = heavyComputation(data);
    self.postMessage(result);
});

function heavyComputation(data) {
    // CPU-intensive işlem
    let result = 0;
    for (let i = 0; i < 1000000000; i++) {
        result += i;
    }
    return result;
}

// 2. Main Thread
const worker = new Worker('worker.js');

worker.addEventListener('message', (e) => {
    console.log('Result from worker:', e.data);
    updateUI(e.data);
});

worker.addEventListener('error', (error) => {
    console.error('Worker error:', error);
});

// 3. Send Data
worker.postMessage({ task: 'calculate', data: [1, 2, 3, 4, 5] });

// 4. Terminate Worker
worker.terminate();

// 5. Shared Worker (Multiple tabs)
const sharedWorker = new SharedWorker('shared-worker.js');
sharedWorker.port.start();
sharedWorker.port.postMessage('Hello from tab 1');

// 6. Worker with Transferable Objects
const buffer = new ArrayBuffer(1024);
const view = new Int32Array(buffer);
worker.postMessage(view, [buffer]); // Transfer ownership

✅ Web Worker Kullanım Alanları

  • ✓ Heavy computations
  • ✓ Image processing
  • ✓ Data parsing
  • ✓ Encryption
  • ✓ Web scraping

Web Workers, JavaScript’in en güçlü özelliklerinden biridir. UI thread’ini bloklamadan heavy işlemler yapın.

— Performance Developer

Related posts:

Use AbortController to Cancel Requests

Use AbortController to Cancel Requests

JavaScript: Fix Promise.race Resolving With a Timeout's Placeholder Value Instead of Ever Propagatin...

JavaScript: Fix Promise.race Resolving With a Timeout's Placeholder Value Instead of Ever Propagatin...

JavaScript Timers Drift Over Time

JavaScript Timers Drift Over Time

Views: 10

Post navigation

C#: Span<T> ile Memory Optimization
SQL: Index Types ve Optimization Teknikleri

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com