Hacker News new | ask | show | jobs
by TheLogothete 3749 days ago
Yeah man. I've never heard of those. They sound like the best thing since sliced bread. Only if they could access the DOM...

Seriously... what are you even talking about? Why do you even mention them? You read single threaded and thought "Quick, I must come up with an answer! I can't let a stranger on the Internet change my opinion!"?

1 comments

So, it's hard to understand exactly what it is you're trying to accomplish and why Web Workers wouldn't work for you because basically every single desktop GUI framework is single-threaded when it comes to actually updating the components on the screen. Win32 uses the GetMessage/TranslateMessage/DispatchMessage event loop. Swing has the UI thread, and then to update the UI from a background thread, you need to call invokeAndWait or invokeLater and pass a Runnable. Cocoa and iOS have Grand Central Dispatch, and to update the UI you pass a block to dispatch_async on a dispatch queue. Android has you call View.post() with a Runnable that contains your UI modifications. WPF has two threads, a rendering one and a UI thread, and you're supposed to pass long-running operations off to a threadpool and then call Invoke or BeginInvoke with a delegate to actually update the UI from them.

Web Workers are exactly this model, applied to the web. It's a dispatch queue running inside a threadpool. To update the DOM, you postMessage back to the UI thread and make your modifications there.

Are you willing to let a stranger on the Internet change your opinion?

This is getting tiresome. You cannot access key objects with webworkers. It's a lipstick on a pig. If you want to kiss it, be my guess, but please do not try misguide other people to do so.