<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          SugarWorkerWebWorker 語(yǔ)法糖

          聯(lián)合創(chuàng)作 · 2023-09-22 08:13

          SugarWorker —— 輕松的使用web多線(xiàn)程技術(shù);

          webWorker

          var lsitWorker = new Worker('core/listWorker.js');
          lsitWorker.onmessage = function(e){     
              if(e.data){
                  listWorker.postMessage('new test data');
              }
              ...(response)
              console.log(e);
              lsitWorker.terminate();
          };
          listWorker.onerror = function(e){
              ...(response)
              console.error(e);
          };
          listWorker.postMessage('test data');

          SugarWorker

          work('core/listWorker.js')
              .back(function(e){         
                  if(e.data){
                      e.post('new test data');
                  }
                  ...(response)
                  console.log(e);
                  e.end();
              })
              .err(function(e){
                  ...(response)
                  console.error(e);
              })
              .post('test data');

          SugarWorker還支持事件定義,方便監(jiān)聽(tīng)另一條線(xiàn)程的狀態(tài)

          work('core/test.js')
              .back(function(e){
                  console.log(e);
              })
              .set('loading',function(e){
                  console.log('loading');
                  console.log(e);
              })
              .post('test data');
          //test.js onmessage = function(e){
              postMessage({
                  eventType : 'loading',
                  data : {...}
                  //some datas     
              });
          }

          通過(guò)worker線(xiàn)程返回對(duì)象,添加eventType屬性,可以在主線(xiàn)程觸發(fā)定義的事件;

          添加eventType的返回?cái)?shù)據(jù),不會(huì)觸發(fā)主線(xiàn)程back方法;

          更多使用方法請(qǐng)查看:https://github.com/kirakiray/SugarWorker

          瀏覽 15
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  波多野结衣福利在线 | 亚洲资源网 | 婷婷成人免费视频 | 成人网站在线 | 亚洲女人操b视频 |