WorkerPool.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>WorkerPool - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">WorkerPool</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>A simple pool for managing Web Workers.</p></div>
  16. </header>
  17. <article>
  18. <h2 class="subsection-title">Import</h2>
  19. <p><span translate="no">WorkerPool</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
  20. <pre><code class="language-js">import { WorkerPool } from 'three/addons/utils/WorkerPool.js';</code></pre>
  21. <div class="container-overview">
  22. <h2>Constructor</h2>
  23. <h3 class="name name-method" id="WorkerPool" translate="no">new <a href="#WorkerPool">WorkerPool</a><span class="signature">( pool : <span class="param-type">number</span> )</span> </h3>
  24. <div class="method">
  25. <div class="description">
  26. <p>Constructs a new Worker pool.</p>
  27. </div>
  28. <table class="params">
  29. <tbody>
  30. <tr>
  31. <td class="name"><code>pool</code></td>
  32. <td class="description last"><p>The size of the pool.<br/>Default is <code>4</code>.</p></td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. </div>
  37. </div>
  38. <h2 class="subsection-title">Classes</h2>
  39. <dl>
  40. <dt><a href="WorkerPool.html">WorkerPool</a></dt>
  41. <dd></dd>
  42. </dl>
  43. <h2 class="subsection-title">Properties</h2>
  44. <div class="member">
  45. <h3 class="name" id="pool" translate="no">.<a href="#pool">pool</a><span class="type-signature"> : number</span> </h3>
  46. <div class="description">
  47. <p>The size of the pool.<br/>Default is <code>4</code>.</p>
  48. </div>
  49. </div>
  50. <div class="member">
  51. <h3 class="name" id="queue" translate="no">.<a href="#queue">queue</a><span class="type-signature"> : Array.&lt;Object></span> </h3>
  52. <div class="description">
  53. <p>A message queue.</p>
  54. </div>
  55. </div>
  56. <div class="member">
  57. <h3 class="name" id="workerCreator" translate="no">.<a href="#workerCreator">workerCreator</a><span class="type-signature"> : function</span> </h3>
  58. <div class="description">
  59. <p>A factory function for creating workers.</p>
  60. </div>
  61. </div>
  62. <div class="member">
  63. <h3 class="name" id="workerStatus" translate="no">.<a href="#workerStatus">workerStatus</a><span class="type-signature"> : number</span> </h3>
  64. <div class="description">
  65. <p>The current worker status.</p>
  66. </div>
  67. </div>
  68. <div class="member">
  69. <h3 class="name" id="workers" translate="no">.<a href="#workers">workers</a><span class="type-signature"> : Array.&lt;Worker></span> </h3>
  70. <div class="description">
  71. <p>An array of Workers.</p>
  72. </div>
  73. </div>
  74. <div class="member">
  75. <h3 class="name" id="workersResolve" translate="no">.<a href="#workersResolve">workersResolve</a><span class="type-signature"> : Array.&lt;function()></span> </h3>
  76. <div class="description">
  77. <p>An array with resolve functions for messages.</p>
  78. </div>
  79. </div>
  80. <h2 class="subsection-title">Methods</h2>
  81. <h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
  82. <div class="method">
  83. <div class="description">
  84. <p>Terminates all Workers of this pool. Call this method whenever this
  85. Worker pool is no longer used in your app.</p>
  86. </div>
  87. </div>
  88. <h3 class="name name-method" id="postMessage" translate="no">.<a href="#postMessage">postMessage</a><span class="signature">( msg : <span class="param-type">Object</span>, transfer : <span class="param-type">Array.&lt;ArrayBuffer></span> )</span><span class="type-signature"> : Promise</span> </h3>
  89. <div class="method">
  90. <div class="description">
  91. <p>Post a message to an idle Worker. If no Worker is available,
  92. the message is pushed into a message queue for later processing.</p>
  93. </div>
  94. <table class="params">
  95. <tbody>
  96. <tr>
  97. <td class="name"><code>msg</code></td>
  98. <td class="description last"><p>The message.</p></td>
  99. </tr>
  100. <tr>
  101. <td class="name"><code>transfer</code></td>
  102. <td class="description last"><p>An array with array buffers for data transfer.</p></td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. <dl class="details">
  107. <dt class="tag-returns"><strong>Returns:</strong> A Promise that resolves when the message has been processed.</dt>
  108. </dl>
  109. </div>
  110. <h3 class="name name-method" id="setWorkerCreator" translate="no">.<a href="#setWorkerCreator">setWorkerCreator</a><span class="signature">( workerCreator : <span class="param-type">function</span> )</span> </h3>
  111. <div class="method">
  112. <div class="description">
  113. <p>Sets a function that is responsible for creating Workers.</p>
  114. </div>
  115. <table class="params">
  116. <tbody>
  117. <tr>
  118. <td class="name"><code>workerCreator</code></td>
  119. <td class="description last"><p>The worker creator function.</p></td>
  120. </tr>
  121. </tbody>
  122. </table>
  123. </div>
  124. <h3 class="name name-method" id="setWorkerLimit" translate="no">.<a href="#setWorkerLimit">setWorkerLimit</a><span class="signature">( pool : <span class="param-type">number</span> )</span> </h3>
  125. <div class="method">
  126. <div class="description">
  127. <p>Sets the Worker limit</p>
  128. </div>
  129. <table class="params">
  130. <tbody>
  131. <tr>
  132. <td class="name"><code>pool</code></td>
  133. <td class="description last"><p>The size of the pool.</p></td>
  134. </tr>
  135. </tbody>
  136. </table>
  137. </div>
  138. <h2 class="subsection-title">Source</h2>
  139. <p>
  140. <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/utils/WorkerPool.js" target="_blank" rel="noopener" translate="no">examples/jsm/utils/WorkerPool.js</a>
  141. </p>
  142. </article>
  143. </section>
  144. <script src="../scripts/linenumber.js"></script>
  145. <script src="../scripts/page.js"></script>
  146. </body>
  147. </html>
粤ICP备19079148号