Added wait helper method
This commit is contained in:
parent
2cd7ccd253
commit
351d0226a2
45
DOCS.md
45
DOCS.md
@ -78,6 +78,7 @@ Emits when a LPF2 Hub device is found.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
* ["button" (button, state)](#BoostHub+event_button)
|
||||
* ["distance" (port, distance)](#BoostHub+event_distance)
|
||||
* ["color" (port, color)](#BoostHub+event_color)
|
||||
@ -164,6 +165,20 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### boostHub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>BoostHub</code>](#BoostHub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
<a name="BoostHub+event_button"></a>
|
||||
|
||||
### "button" (button, state)
|
||||
@ -239,6 +254,7 @@ Emits when a rotation sensor is activated.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
* ["button" (button, state)](#WeDo2Hub+event_button)
|
||||
* ["distance" (port, distance)](#WeDo2Hub+event_distance)
|
||||
* ["color" (port, color)](#WeDo2Hub+event_color)
|
||||
@ -324,6 +340,20 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### weDo2Hub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
<a name="WeDo2Hub+event_button"></a>
|
||||
|
||||
### "button" (button, state)
|
||||
@ -396,6 +426,7 @@ Emits when a rotation sensor is activated.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -436,3 +467,17 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### hub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>Hub</code>](#Hub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
|
45
README.md
45
README.md
@ -118,6 +118,7 @@ Emits when a LPF2 Hub device is found.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
* ["button" (button, state)](#BoostHub+event_button)
|
||||
* ["distance" (port, distance)](#BoostHub+event_distance)
|
||||
* ["color" (port, color)](#BoostHub+event_color)
|
||||
@ -204,6 +205,20 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### boostHub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>BoostHub</code>](#BoostHub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
<a name="BoostHub+event_button"></a>
|
||||
|
||||
### "button" (button, state)
|
||||
@ -279,6 +294,7 @@ Emits when a rotation sensor is activated.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
* ["button" (button, state)](#WeDo2Hub+event_button)
|
||||
* ["distance" (port, distance)](#WeDo2Hub+event_distance)
|
||||
* ["color" (port, color)](#WeDo2Hub+event_color)
|
||||
@ -364,6 +380,20 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### weDo2Hub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>WeDo2Hub</code>](#WeDo2Hub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
<a name="WeDo2Hub+event_button"></a>
|
||||
|
||||
### "button" (button, state)
|
||||
@ -436,6 +466,7 @@ Emits when a rotation sensor is activated.
|
||||
* [.disconnect()](#Hub+disconnect) ⇒ <code>Promise</code>
|
||||
* [.subscribe(port, [mode])](#Hub+subscribe) ⇒ <code>Promise</code>
|
||||
* [.unsubscribe(port)](#Hub+unsubscribe) ⇒ <code>Promise</code>
|
||||
* [.wait(delay)](#Hub+wait) ⇒ <code>Promise</code>
|
||||
|
||||
<a name="Hub+connect"></a>
|
||||
|
||||
@ -476,3 +507,17 @@ Unsubscribe to sensor notifications on a given port.
|
||||
| --- | --- |
|
||||
| port | <code>string</code> |
|
||||
|
||||
<a name="Hub+wait"></a>
|
||||
|
||||
### hub.wait(delay) ⇒ <code>Promise</code>
|
||||
Wait a given amount of time.
|
||||
|
||||
This is a helper method to make it easier to add delays into a chain of commands.
|
||||
|
||||
**Kind**: instance method of [<code>Hub</code>](#Hub)
|
||||
**Returns**: <code>Promise</code> - Resolved after the delay is finished.
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| delay | <code>number</code> | How long to wait (in milliseconds). |
|
||||
|
||||
|
15
hub.ts
15
hub.ts
@ -156,6 +156,21 @@ export class Hub extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wait a given amount of time.
|
||||
*
|
||||
* This is a helper method to make it easier to add delays into a chain of commands.
|
||||
* @method Hub#wait
|
||||
* @param {number} delay How long to wait (in milliseconds).
|
||||
* @returns {Promise} Resolved after the delay is finished.
|
||||
*/
|
||||
public wait (delay: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected _subscribeToCharacteristic (characteristic: Characteristic, callback: (data: Buffer) => void) {
|
||||
characteristic.on("data", (data: Buffer) => {
|
||||
return callback(data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user