Skip to content

Commit

Permalink
Documentation for once
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Dec 22, 2023
1 parent 9af1aeb commit 20e11d7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/en/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [log - Gives out the message into log](#log---gives-out-the-message-into-log)
- [exec - execute some OS command, like "cp file1 file2"](#exec---execute-some-os-command-like-cp-file1-file2)
- [on - Subscribe on changes or updates of some state](#on---subscribe-on-changes-or-updates-of-some-state)
- [once](#once)
- [subscribe - same as on](#subscribe---same-as-on)
- [unsubscribe](#unsubscribe)
- [getSubscriptions](#getsubscriptions)
Expand Down Expand Up @@ -220,10 +221,10 @@ let timer;
createState('counter', 0);

// On change
on('adapter.0.device.channel.sensor', function (data) {
on('adapter.0.device.channel.sensor', (data) => {
// But not ofter than 30 seconds
if (!timer) {
timer = setTimeout(function () {
timer = setTimeout(() => {
timer = null;
}, 30000);

Expand Down Expand Up @@ -391,6 +392,13 @@ Function `on` returns handler back. This handler can be used by unsubscribe.

*Notice:* from 4.3.2 it is possible to write a type of trigger as second parameter: `on('my.id.0', 'any', obj => console.log(obj.state.val));`

### once
Registers a one-time subscription which automatically unsubscribes after the first invocation. Same as [on](#on---subscribe-on-changes-or-updates-of-some-state), but just executed once.

```js
once(pattern, callback);
```

### subscribe - same as **[on](#on---subscribe-on-changes-or-updates-of-some-state)**

### unsubscribe
Expand Down

0 comments on commit 20e11d7

Please sign in to comment.