Skip to content

Commit 8ab29ca

Browse files
refactor: start experimenting with extending invokeAction
1 parent 38c8e91 commit 8ab29ca

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

index.html

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,71 @@ <h2>The <dfn>InteractionOutput</dfn> interface</h2>
12751275
</ol>
12761276
</section>
12771277
</section>
1278-
<section> <h3>Using {{InteractionInput}} and {{InteractionOutput}}</h3>
1278+
1279+
<section data-dfn-for="ActionInteractionOutput">
1280+
<h2>The <dfn>ActionInteractionOutput</dfn> interface</h2>
1281+
<p>
1282+
Belongs to the <a>WoT Consumer</a> conformance class.
1283+
An {{ActionInteractionOutput}} object is always created by the implementations
1284+
and exposes the data returned from <a>WoT Interactions</a> to application
1285+
scripts.
1286+
</p>
1287+
<p>
1288+
This interface exposes an action status object. Its implementation
1289+
will allow cancelling asynchronous actions and report the status of a long running action.
1290+
</p>
1291+
<pre class="idl">
1292+
enum ActionStatus {
1293+
/* "pending", Profile has pending. Not sure what it would mean? */
1294+
"running",
1295+
"success", /* Profile uses completed? */
1296+
"error" /* Profile uses failed? */
1297+
};
1298+
1299+
[SecureContext, Exposed=(Window,Worker)]
1300+
interface ActionInteractionOutput : InteractionOutput {
1301+
readonly attribute object? error;
1302+
Promise&lt;ActionStatus&gt; status();
1303+
Promise&lt;undefined&gt; cancel();
1304+
};
1305+
</pre>
1306+
<p>
1307+
The <dfn>error</dfn> property represents a possible error, initially `null`.
1308+
</p>
1309+
<p class="ednote" title="Should state be a function or an attribute only?">
1310+
1311+
</p>
1312+
<p class="ednote" title="Additional action object functions needed?">
1313+
Should we allow pause/resume also? TD has no notion of it.
1314+
</p>
1315+
<section><h3>The <dfn>status()</dfn> function</h3>
1316+
Reports the status of an <a>Action</a> (one of <code>running</code>, <code>success</code> or <code>error</code>) or rejects on error. The method MUST run the following steps:
1317+
<ol>
1318+
<li>
1319+
Return a {{Promise}} |promise:Promise| and execute the next steps
1320+
[=in parallel=].
1321+
</li>
1322+
<li>
1323+
TODO
1324+
</li>
1325+
</ol>
1326+
</section>
1327+
<section><h3>The <dfn>cancel()</dfn> function</h3>
1328+
Cancels a running WoT <a>Action</a> or rejects on error. The method MUST run the following steps:
1329+
<ol>
1330+
<li>
1331+
Return a {{Promise}} |promise:Promise| and execute the next steps
1332+
[=in parallel=].
1333+
</li>
1334+
<li>
1335+
TODO
1336+
</li>
1337+
</ol>
1338+
</section>
1339+
1340+
</section>
1341+
1342+
<section> <h3>Using {{InteractionInput}}, {{InteractionOutput}} and {{ActionInteractionOutput}}</h3>
12791343
<p>
12801344
As illustrated in the next pictures, the {{InteractionOutput}} interface
12811345
is used every time implementations provide data to scripts, while
@@ -1323,7 +1387,7 @@ <h2>The <dfn>InteractionOutput</dfn> interface</h2>
13231387
<p>
13241388
When a {{ConsumedThing}} invokes an <a>Action</a>, it provides the
13251389
parameters as {{InteractionInput}} and receives the output of the
1326-
<a>Action</a> as an {{InteractionOutput}} object.
1390+
<a>Action</a> as an {{ActionInteractionOutput}} object.
13271391
</p>
13281392
<p>
13291393
An {{ExposedThing}} <a href="#the-actionhandler-callback">
@@ -1386,7 +1450,7 @@ <h2>The <dfn>ConsumedThing</dfn> interface</h2>
13861450
/*Promise&lt;undefined&gt; writeAllProperties(
13871451
PropertyWriteMap valueMap,
13881452
optional InteractionOptions options = {});*/
1389-
Promise&lt;InteractionOutput&gt; invokeAction(DOMString actionName,
1453+
Promise&lt;ActionInteractionOutput&gt; invokeAction(DOMString actionName,
13901454
optional InteractionInput params = {},
13911455
optional InteractionOptions options = {});
13921456
Promise&lt;Subscription&gt; observeProperty(DOMString name,

typescript/scripting-api/index.d.ts

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

91+
export enum ActionStatus { "running", "success", "error" }
92+
93+
export interface ActionInteractionOutput extends InteractionOutput {
94+
error?: Error;
95+
status(): Promise<ActionStatus>
96+
cancel(): Promise<void>
97+
}
98+
9199
export interface Subscription {
92100
active:boolean,
93101
stop(options?: InteractionOptions):Promise<void>
@@ -140,9 +148,9 @@ declare namespace WoT {
140148
* Makes a request for invoking an Action and return the result.
141149
* Takes as arguments actionName, optionally params and optionally options.
142150
* It returns a Promise that resolves with the result of the Action represented
143-
* as an InteractionOutput object, or rejects with an error.
151+
* as an ActionInteractionOutput object, or rejects with an error.
144152
*/
145-
invokeAction(actionName: string, params?: InteractionInput, options?: InteractionOptions): Promise<undefined | InteractionOutput>;
153+
invokeAction(actionName: string, params?: InteractionInput, options?: InteractionOptions): Promise<undefined | ActionInteractionOutput>;
146154

147155
/**
148156
* Makes a request for Property value change notifications.

0 commit comments

Comments
 (0)