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

932 lines
78 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>WorkerDispatch - 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">WorkerDispatch</h1>
<section>
<header>
<h2>
WorkerDispatch
</h2>
<div class="class-description"><p>This class provides a Worker with the means to participate in the message dispatch system managed by CentralDispatch.
From any context in the messaging system, the dispatcher's &quot;call&quot; method can call any method on any &quot;service&quot;
provided in any participating context. The dispatch system will forward function arguments and return values across
worker boundaries as needed.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="WorkerDispatch"><span class="type-signature"></span>new WorkerDispatch<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>{<a href="CentralDispatch.html">CentralDispatch</a>}</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_connectionPromise"><span class="type-signature">(private) </span>_connectionPromise<span class="type-signature"> :Promise</span></h4>
<dl class="details">
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>{waitForConnection}</li>
</ul>
</dd>
</dl>
<div class="description">
<p>This promise will be resolved when we have successfully connected to central dispatch.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Promise</span>
</li>
</ul>
<h4 class="name" id="services"><span class="type-signature"></span>services<span class="type-signature"> :object</span></h4>
<dl class="details">
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>{setService}</li>
</ul>
</dd>
</dl>
<div class="description">
<p>Map of service name to local service provider.
If a service is not listed here, it is assumed to be provided by another context (another Worker or the main
thread).</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">object</span>
</li>
</ul>
<h4 class="name" id="waitForConnection"><span class="type-signature"></span>waitForConnection<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>dispatch.waitForConnection.then(() => {
dispatch.call('myService', 'hello');
})</code></pre>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_getServiceProvider"><span class="type-signature">(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="_onDispatchMessage"><span class="type-signature">(protected) </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="setService"><span class="type-signature"></span>setService<span class="signature">(service, provider)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set a local object as the global provider of the specified service.
WARNING: Any method on the provider can be called from any worker within the dispatch system.</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>a globally unique string identifying this service. Examples: 'vm', 'gui', 'extension9'.</p></td>
</tr>
<tr>
<td class="name"><code>provider</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>a local object which provides this service.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>a promise which will resolve once the service is registered.</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>