Skip to content

Commit 81453c9

Browse files
authored
Merge pull request #561 from danielpeintner/issue-555
Extended return type of invokeAction()
2 parents ad351eb + 699aa6b commit 81453c9

File tree

2 files changed

+88
-5
lines changed

2 files changed

+88
-5
lines changed

index.html

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,80 @@ <h2>The <dfn>InteractionOutput</dfn> interface</h2>
12861286
</ol>
12871287
</section>
12881288
</section>
1289-
<section> <h3>Using {{InteractionInput}} and {{InteractionOutput}}</h3>
1289+
1290+
<section data-dfn-for="ActionInteractionOutput">
1291+
<h2>The <dfn>ActionInteractionOutput</dfn> interface</h2>
1292+
<p>
1293+
Belongs to the <a>WoT Consumer</a> conformance class.
1294+
An {{ActionInteractionOutput}} object is always created by a consumer implementation
1295+
and exposes functionality to interact with long running (asynchronous) actions.<br />
1296+
Note: The output of a synchronous action MAY be limited to the functionality of a regular {{InteractionOutput}} object, e.g., invoking the `cancel()` method might not have an effect.
1297+
</p>
1298+
<p>
1299+
This interface exposes functions which
1300+
will allow cancelling asynchronous actions and query the status of a long running action.
1301+
</p>
1302+
<pre class="idl">
1303+
/**
1304+
* Note: retrieving the result of an action via the implicit InteractionOutput interface
1305+
* will only work after the action has been completed
1306+
*/
1307+
[SecureContext, Exposed=(Window,Worker)]
1308+
interface ActionInteractionOutput : InteractionOutput {
1309+
Promise&lt;InteractionOutput&gt; query(
1310+
optional InteractionInput params = {},
1311+
optional InteractionOptions options = {});
1312+
Promise&lt;undefined&gt; cancel(
1313+
optional InteractionInput params = {},
1314+
optional InteractionOptions options = {});
1315+
};
1316+
</pre>
1317+
1318+
</p>
1319+
1320+
<section><h3>The <dfn>query()</dfn> function</h3>
1321+
Reports the status of an <a>Action</a>, or rejects on error. The method MUST run the following steps:
1322+
<ol>
1323+
<li>
1324+
Return a {{Promise}} |promise:Promise| and execute the next steps
1325+
[=in parallel=].
1326+
</li>
1327+
<li>
1328+
If invoking this method is not supported (e.g., synchronous action)
1329+
[=reject=] |promise| with a {{NotSupportedError}} and stop.
1330+
</li>
1331+
<li>
1332+
Let |res| be the result of making a request to the underlying platform (via the <a>Protocol Bindings</a>) to query the <a>Action</a> status given optional |params| and |options|. If quering |res| fails, [=reject=] |promise| with {{OperationError}} and stop.
1333+
</li>
1334+
<li>
1335+
[=Resolve=] |promise| with |res|.
1336+
</li>
1337+
</ol>
1338+
</section>
1339+
<section><h3>The <dfn>cancel()</dfn> function</h3>
1340+
Cancels a running WoT <a>Action</a>, or rejects on error. The method MUST run the following steps:
1341+
<ol>
1342+
<li>
1343+
Return a {{Promise}} |promise:Promise| and execute the next steps
1344+
[=in parallel=].
1345+
</li>
1346+
<li>
1347+
If invoking this method is not supported (e.g., because the action is synchronous)
1348+
[=reject=] |promise| with a {{NotSupportedError}} and stop.
1349+
</li>
1350+
<li>
1351+
Make a request to the underlying platform (via the <a>Protocol Bindings</a>) to cancel the <a>Action</a> given optional |params| and |options|.
1352+
If cancelling fails, [=reject=] |promise| with {{OperationError}} and stop.
1353+
</li>
1354+
<li>
1355+
[=Resolve=] |promise|</a>.
1356+
</li>
1357+
</ol>
1358+
</section>
1359+
1360+
</section>
1361+
1362+
<section> <h3>Using {{InteractionInput}}, {{InteractionOutput}} and {{ActionInteractionOutput}}</h3>
12901363
<p>
12911364
As illustrated in the next pictures, the {{InteractionOutput}} interface
12921365
is used every time implementations provide data to scripts, while
@@ -1334,7 +1407,7 @@ <h2>The <dfn>InteractionOutput</dfn> interface</h2>
13341407
<p>
13351408
When a {{ConsumedThing}} invokes an <a>Action</a>, it provides the
13361409
parameters as {{InteractionInput}} and receives the output of the
1337-
<a>Action</a> as an {{InteractionOutput}} object.
1410+
<a>Action</a> as an {{ActionInteractionOutput}} object.
13381411
</p>
13391412
<p>
13401413
An {{ExposedThing}} <a href="#the-actionhandler-callback">
@@ -1397,7 +1470,7 @@ <h2>The <dfn>ConsumedThing</dfn> interface</h2>
13971470
/*Promise&lt;undefined&gt; writeAllProperties(
13981471
PropertyWriteMap valueMap,
13991472
optional InteractionOptions options = {});*/
1400-
Promise&lt;InteractionOutput&gt; invokeAction(DOMString actionName,
1473+
Promise&lt;ActionInteractionOutput&gt; invokeAction(DOMString actionName,
14011474
optional InteractionInput params = {},
14021475
optional InteractionOptions options = {});
14031476
Promise&lt;Subscription&gt; observeProperty(DOMString name,

typescript/scripting-api/index.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ declare namespace WoT {
8888
value(): Promise<DataSchemaValue>;
8989
}
9090

91+
/**
92+
* Note: retrieving the result of an action via the implicit InteractionOutput interface will only work after the action has been completed
93+
*/
94+
export interface ActionInteractionOutput extends InteractionOutput {
95+
// query the status of a running action
96+
query(params?: InteractionInput, options?: InteractionOptions): Promise<InteractionOutput>
97+
// cancel a pending/running action
98+
cancel(params?: InteractionInput, options?: InteractionOptions): Promise<void>
99+
}
100+
91101
export interface Subscription {
92102
active:boolean,
93103
stop(options?: InteractionOptions):Promise<void>
@@ -140,9 +150,9 @@ declare namespace WoT {
140150
* Makes a request for invoking an Action and return the result.
141151
* Takes as arguments actionName, optionally params and optionally options.
142152
* It returns a Promise that resolves with the result of the Action represented
143-
* as an InteractionOutput object, or rejects with an error.
153+
* as an ActionInteractionOutput object, or rejects with an error.
144154
*/
145-
invokeAction(actionName: string, params?: InteractionInput, options?: InteractionOptions): Promise<undefined | InteractionOutput>;
155+
invokeAction(actionName: string, params?: InteractionInput, options?: InteractionOptions): Promise<undefined | ActionInteractionOutput>;
146156

147157
/**
148158
* Makes a request for Property value change notifications.

0 commit comments

Comments
 (0)