• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RxJS in Action: RxJS and Webworkers?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used RxJS (mostly copy and past, I confess) with ng/rx and I loved it.
Looking at the current PWA fashion it seems that state of the art is to have all network communication done in a webworker.
How does that work in RxJS? Can an Observable be shared across the boundary between webworker and main thread?
Is there some sample?
 
Author
Posts: 8
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very good question! It is something I entertained as well when I first learned about Web Workers, since they seem very conceptually related to threads.

The Web Worker interface however I think would make it difficult for this type of integration, since it runs with its own script context and to my knowledge it only allows the transfer of strict json or Transferrable, whereas with a Scheduler we would need to also pass arbitrary tasks to be executed. So while we tend to think of WebWorkers as multi-threading for JavaScript, I think conceptually they are closer to a light-weight process type instead.

That's not to say we can't use Web Workers to perform some heavy lifting, we would just use a different mechanism. Here is an admittedly toy example:



In the above we create what I like to call a "wrinkle in space and time" to create a Subject appears to be mapping inputs to outputs with as we normally see with our standard Subject, however in this case the inbound message is actually going to the Web Worker and the outbound message is the result sent back from the Web Worker, making it transparently inline with your stream.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic