Skip to content

Commit 445a978

Browse files
committed
$delay docs
1 parent ad23fb0 commit 445a978

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

LANGUAGE.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,42 @@ or using reference:
307307

308308

309309
## Delayed evaluation with `$delay`
310+
311+
`$delay` instruction can be used to delay the start of evaluation of any script. That can be useful, for example, if you need to ensure that one script starts evaluating after another script starts, but you don't need for it to wait for the completion (as in sequential processing):
312+
313+
```JSON
314+
{
315+
"res1": {
316+
"$exec": "router",
317+
"$method": "get",
318+
"$args": { "path": "/resource/1" }
319+
},
320+
"res2": {
321+
"$delay": {
322+
"$exec": "router",
323+
"$method": "get",
324+
"$args": { "path": "/resource/2" }
325+
},
326+
"$wait": 50
327+
}
328+
}
329+
```
330+
331+
The evaluation result will be the same as without `$delay` istruction, but the second "$exec" instruction will start executing at least 50 milliseconds later than the first.
332+
333+
This instruction can also be used to create asynchronous value from synchronous value. For example if some executor expects an asynchronous value as an argument and you want to pass a constant, you can use `$delay`:
334+
335+
```JSON
336+
{
337+
"$exec": "logger",
338+
"$method": "resolve",
339+
"$args": {
340+
"message": "Resolved",
341+
"asyncValue": { "$delay": "test", "$wait": 1000 }
342+
}
343+
}
344+
```
345+
346+
In the example above a hypothetical logger logs message when asynchronous value is resolved. `$delay` instruction result is an asynchrnous value that resolves 1 second after its evaluation with the value `"test"`.
347+
348+
`$wait` keyword is optional, the default is 0. It means that the interpreter should schedule the script evaluation as soon as possible but do not execute it immediately.

0 commit comments

Comments
 (0)