Loading ...
Sorry, an error occurred while loading the content.

934Re: [yui3] YUI3 and web workers

Expand Messages
  • Mark Jarecki
    Dec 15, 2009
    • 0 Attachment
      My current method, in the following simplified example (with some components omitted for clarity), works, but maybe a little clunky.

      I'm also wondering how best to bring some of the functionality of YUI3 into the worker.

      Thanks,

      Mark

      HTML
      <!DOCTYPE html>
      <html lang="en">
      <head>
      <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <script type="text/javascript" src="path/to/yui/build/yui/yui-min.js"></script>
      </head>
      <body>
      <script type="text/javascript">
      YUI({

      base: 'path/to/yui/build/',
      combine: false,
      modules: {
      worker: {fullpath:'path/to/worker.js'},
      view: {fullpath:'path/to/js/view.js', requires: ['dd-constrain']},
      manager: {fullpath:'path/to/manager.js', requires: ['base', 'view', 'worker']}
      },
      timeout: 10000

      }).use('manager', function(Y) {

      Y.on("domready", function(){ 

      var ManagerPages = Y.Base.build("managerPages", Y.Manager, [Y.ManagerPages]);
      var mp = new ManagerPages();
      }, Y);

      });
      </script>
      </body>
      </html>

      manager.js
      YUI.add("manager", function(Y) {

          var Manager,
          MANAGER = 'manager',
          $D = Y.DOM,
          $L = Y.Lang,
          $J = Y.JSON,
          isBoolean = $L.isBoolean;

         Manager = function(config) { Manager.superclass.constructor.apply(this, arguments); };

      Y.mix(Manager, {
      NAME: MANAGER,
      ATTRS: {

      someATTR: {
      value: false,
      validator: isBoolean
      }
      }        
      });

      Y.extend(Manager, Y.Base, {
      _worker: null,
      initializer: function(config) {

      //initialise exchange worker
      try {

      this. _worker = new Worker('http://127.0.0.1/static/js/exchangeworker.js');
      this. _worker.onmessage = function(e) {
      if (e.data == "nay") {
      alert("the worker responded");
      };
      }
      this. _worker.postMessage("yay");

      } catch(e) {

      alert('Unable to create worker: ' + e.message);
      return;
      }
      }

      });

      Y.Manager = Manager;

      }, "3.0.0");


      worker.js
      onmessage = function(e){
      postMessage("nay");
      };

      On 15/12/2009, at 6:45 PM, Mark Jarecki wrote:

       

      Hi there,

      I was wondering if someone might have a basic example of getting web workers working with YUI3.

      Cheers

      Mark


    • Show all 2 messages in this topic