easy-scratch/doc/scratch-vm/SharedDispatch.html

2382 lines
95 KiB
HTML
Raw Normal View History

2025-02-12 12:27:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SharedDispatch - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="-_StackFrame.html">_StackFrame</a><ul class='methods'><li data-type='method'><a href="-_StackFrame.html#.create">create</a></li><li data-type='method'><a href="-_StackFrame.html#.release">release</a></li><li data-type='method'><a href="-_StackFrame.html#reset">reset</a></li><li data-type='method'><a href="-_StackFrame.html#reuse">reuse</a></li></ul></li><li><a href="BLE.html">BLE</a><ul class='methods'><li data-type='method'><a href="BLE.html#connectPeripheral">connectPeripheral</a></li><li data-type='method'><a href="BLE.html#didReceiveCall">didReceiveCall</a></li><li data-type='method'><a href="BLE.html#disconnect">disconnect</a></li><li data-type='method'><a href="BLE.html#handleDisconnectError">handleDisconnectError</a></li><li data-type='method'><a href="BLE.html#isConnected">isConnected</a></li><li data-type='method'><a href="BLE.html#read">read</a></li><li data-type='method'><a href="BLE.html#requestPeripheral">requestPeripheral</a></li><li data-type='method'><a href="BLE.html#startNotifications">startNotifications</a></li><li data-type='method'><a href="BLE.html#write">write</a></li></ul></li><li><a href="BlockCached.html">BlockCached</a></li><li><a href="Blocks.html">Blocks</a><ul class='methods'><li data-type='method'><a href="Blocks.html#_addScript">_addScript</a></li><li data-type='method'><a href="Blocks.html#_deleteScript">_deleteScript</a></li><li data-type='method'><a href="Blocks.html#_getBackdropField">_getBackdropField</a></li><li data-type='method'><a href="Blocks.html#_getBlockParams">_getBlockParams</a></li><li data-type='method'><a href="Blocks.html#_getCostumeField">_getCostumeField</a></li><li data-type='method'><a href="Blocks.html#_getCustomBlockInternal">_getCustomBlockInternal</a></li><li data-type='method'><a href="Blocks.html#_getSoundField">_getSoundField</a></li><li data-type='method'><a href="Blocks.html#_getSpriteField">_getSpriteField</a></li><li data-type='method'><a href="Blocks.html#blocklyListen">blocklyListen</a></li><li data-type='method'><a href="Blocks.html#blockToXML">blockToXML</a></li><li data-type='method'><a href="Blocks.html#changeBlock">changeBlock</a></li><li data-type='method'><a href="Blocks.html#createBlock">createBlock</a></li><li data-type='method'><a href="Blocks.html#deleteBlock">deleteBlock</a></li><li data-type='method'><a href="Blocks.html#emitProjectChanged">emitProjectChanged</a></li><li data-type='method'><a href="Blocks.html#getAllVariableAndListReferences">getAllVariableAndListReferences</a></li><li data-type='method'><a href="Blocks.html#getBlock">getBlock</a></li><li data-type='method'><a href="Blocks.html#getBranch">getBranch</a></li><li data-type='method'><a href="Blocks.html#getFields">getFields</a></li><li data-type='method'><a href="Blocks.html#getInputs">getInputs</a></li><li data-type='method'><a href="Blocks.html#getMutation">getMutation</a></li><li data-type='method'><a href="Blocks.html#getNextBlock">getNextBlock</a></li><li data-type='method'><a href="Blocks.html#getOpcode">getOpcode</a></li><li data-type='method'><a href="Blocks.html#getProcedureDefinition">getProcedureDefinition</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesAndIds">getProcedureParamNamesAndIds</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesIdsAndDefaults">getProcedureParamNamesIdsAndDefaults</a></li><li data-type='method'><a href="Blocks.html#getScripts">getScripts</a></li><li data-type='method'><a href="Blocks.html#getTopLevelScript">getTopLevelScript</a></li><li data-type='method'><a href="Blocks.html#moveBlock">moveBlock</a></li><li data-type='method'><a href="Blocks.html#mutationToXML">mutationToXML</a></li><li data-type='method'><a href="Blocks.html#resetCache">resetCache</a></li><li data-type='method'><a href="Blocks.html#runAllMonitored">runAllMonitored</a></li><li data-type='method'><a href="Blocks.html#toXML">toXML</a></li><li data-type='method'><a href="Blocks.html#updateAssetName">updateAssetName</a></li><li data-type='method'><a href
</nav>
<div id="main">
<h1 class="page-title">SharedDispatch</h1>
<section>
<header>
<h2>
SharedDispatch
</h2>
<div class="class-description"><p>The SharedDispatch class is responsible for dispatch features shared by
<a href="CentralDispatch.html">CentralDispatch</a> and <a href="WorkerDispatch.html">WorkerDispatch</a>.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="SharedDispatch"><span class="type-signature"></span>new SharedDispatch<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="callbacks"><span class="type-signature"></span>callbacks<span class="type-signature"> :Array.&lt;Array.&lt;function()>></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>List of callback registrations for promises waiting for a response from a call to a service on another
worker. A callback registration is an array of [resolve,reject] Promise functions.
Calls to local services don't enter this list.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.&lt;Array.&lt;function()>></span>
</li>
</ul>
<h4 class="name" id="nextResponseId"><span class="type-signature"></span>nextResponseId<span class="type-signature"> :int</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The next response ID to be used.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">int</span>
</li>
</ul>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_deliverResponse"><span class="type-signature">(protected) </span>_deliverResponse<span class="signature">(responseId, message)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Deliver call response from a worker. This should only be called as the result of a message from a worker.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>responseId</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="description last"><p>the response ID of the callback set to call.</p></td>
</tr>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type"><a href="global.html#DispatchResponseMessage">DispatchResponseMessage</a></span>
</td>
<td class="description last"><p>the message containing the response value(s).</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="_getServiceProvider"><span class="type-signature">(abstract, protected) </span>_getServiceProvider<span class="signature">(service)</span><span class="type-signature"> &rarr; {Object}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Fetch the service provider object for a particular service name.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the name of the service to look up</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>the means to contact the service, if found</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Object</span>
</dd>
</dl>
<h4 class="name" id="_isRemoteService"><span class="type-signature">(private) </span>_isRemoteService<span class="signature">(service)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Check if a particular service lives on another worker.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the service to check.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>true if the service is remote (calls must cross a Worker boundary), false otherwise.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id="_onDispatchMessage"><span class="type-signature">(abstract, private) </span>_onDispatchMessage<span class="signature">(worker, message)</span><span class="type-signature"> &rarr; {Promise|undefined}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Handle a call message sent to the dispatch service itself</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>worker</code></td>
<td class="type">
<span class="param-type">Worker</span>
</td>
<td class="description last"><p>the worker which sent the message.</p></td>
</tr>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type"><a href="global.html#DispatchCallMessage">DispatchCallMessage</a></span>
</td>
<td class="description last"><p>the message to be handled.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise for the results of this operation, if appropriate</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
|
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="_onMessage"><span class="type-signature">(protected) </span>_onMessage<span class="signature">(worker, event)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Handle a message event received from a connected worker.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>worker</code></td>
<td class="type">
<span class="param-type">Worker</span>
</td>
<td class="description last"><p>the worker which sent the message, or the global object if running in a worker.</p></td>
</tr>
<tr>
<td class="name"><code>event</code></td>
<td class="type">
<span class="param-type">MessageEvent</span>
</td>
<td class="description last"><p>the message event to be handled.</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="_remoteCall"><span class="type-signature"></span>_remoteCall<span class="signature">(provider, service, method, &hellip;args<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Like call, but force the call to be posted through a particular communication channel.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>provider</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>send the call through this object's <code>postMessage</code> function.</p></td>
</tr>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the service.</p></td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the method.</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
&lt;optional><br>
&lt;repeatable><br>
</td>
<td class="description last"><p>the arguments to be copied to the method, if any.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise for the return value of the service method.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="_remoteTransferCall"><span class="type-signature"></span>_remoteTransferCall<span class="signature">(provider, service, method, transfer<span class="signature-attributes">opt</span>, &hellip;args<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Like transferCall, but force the call to be posted through a particular communication channel.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>provider</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>send the call through this object's <code>postMessage</code> function.</p></td>
</tr>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the service.</p></td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the method.</p></td>
</tr>
<tr>
<td class="name"><code>transfer</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>objects to be transferred instead of copied. Must be present in <code>args</code> to be useful.</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
&lt;optional><br>
&lt;repeatable><br>
</td>
<td class="description last"><p>the arguments to be copied to the method, if any.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise for the return value of the service method.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="_storeCallbacks"><span class="type-signature">(protected) </span>_storeCallbacks<span class="signature">(resolve, reject)</span><span class="type-signature"> &rarr; {*}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Store callback functions pending a response message.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>resolve</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"><p>function to call if the service method returns.</p></td>
</tr>
<tr>
<td class="name"><code>reject</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"><p>function to call if the service method throws.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a unique response ID for this set of callbacks. See _deliverResponse.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="call"><span class="type-signature"></span>call<span class="signature">(service, method, &hellip;args<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Call a particular method on a particular service, regardless of whether that service is provided locally or on
a worker. If the service is provided by a worker, the <code>args</code> will be copied using the Structured Clone
algorithm, except for any items which are also in the <code>transfer</code> list. Ownership of those items will be
transferred to the worker, and they should not be used after this call.</p>
</div>
<h5>Example</h5>
<pre class="prettyprint"><code>dispatcher.call('vm', 'setData', 'cat', 42);
// this finds the worker for the 'vm' service, then on that worker calls:
vm.setData('cat', 42);</code></pre>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the service.</p></td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the method.</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
&lt;optional><br>
&lt;repeatable><br>
</td>
<td class="description last"><p>the arguments to be copied to the method, if any.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise for the return value of the service method.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="transferCall"><span class="type-signature"></span>transferCall<span class="signature">(service, method, transfer<span class="signature-attributes">opt</span>, &hellip;args<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Call a particular method on a particular service, regardless of whether that service is provided locally or on
a worker. If the service is provided by a worker, the <code>args</code> will be copied using the Structured Clone
algorithm, except for any items which are also in the <code>transfer</code> list. Ownership of those items will be
transferred to the worker, and they should not be used after this call.</p>
</div>
<h5>Example</h5>
<pre class="prettyprint"><code>dispatcher.transferCall('vm', 'setData', [myArrayBuffer], 'cat', myArrayBuffer);
// this finds the worker for the 'vm' service, transfers `myArrayBuffer` to it, then on that worker calls:
vm.setData('cat', myArrayBuffer);</code></pre>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>service</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the service.</p></td>
</tr>
<tr>
<td class="name"><code>method</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>the name of the method.</p></td>
</tr>
<tr>
<td class="name"><code>transfer</code></td>
<td class="type">
<span class="param-type">Array</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>objects to be transferred instead of copied. Must be present in <code>args</code> to be useful.</p></td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="attributes">
&lt;optional><br>
&lt;repeatable><br>
</td>
<td class="description last"><p>the arguments to be copied to the method, if any.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise for the return value of the service method.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>