4
4
5
5
The simplest script in JSONScript is a single instruction that calls an external executor method with some arguments:
6
6
7
- ``` JSON
7
+ ``` json
8
8
{
9
9
"$exec" : " router" ,
10
10
"$method" : " get" ,
@@ -40,7 +40,7 @@ An asynchronous value is a value that is currently not available and will be ava
40
40
41
41
JSONScript can include several instructions that will be executed sequentially:
42
42
43
- ``` JSON
43
+ ``` json
44
44
[
45
45
{
46
46
"$exec" : " router" ,
@@ -65,7 +65,7 @@ Sequential evaluation is not limited to executing individual instructions - any
65
65
66
66
For example, this script does the same as the script above for two resources:
67
67
68
- ``` JSON
68
+ ``` json
69
69
[
70
70
[
71
71
{
@@ -101,7 +101,7 @@ The result of this script evaluation is the array of two arrays containing two i
101
101
102
102
JSONScript can include several instructions that will be executed in parallel:
103
103
104
- ``` JSON
104
+ ``` json
105
105
{
106
106
"res1" : {
107
107
"$exec" : " router" ,
@@ -126,7 +126,7 @@ Parallel evaluation is not limited to executing individual instructions - any sc
126
126
127
127
For example, the script below is similar to the example in the previous section that updates two resources but it does it in parallel:
128
128
129
- ``` JSON
129
+ ``` json
130
130
{
131
131
"res1" : [
132
132
{
@@ -168,7 +168,7 @@ Let's see what other instructions are defined in JSONScript core.
168
168
169
169
During the evaluation the script can use the data instance passed to the interpeter in addition to the script:
170
170
171
- ``` JSON
171
+ ``` json
172
172
[
173
173
{
174
174
"$exec" : " router" ,
@@ -185,7 +185,7 @@ During the evaluation the script can use the data instance passed to the interpe
185
185
186
186
Data instance:
187
187
188
- ``` JSON
188
+ ``` json
189
189
{
190
190
"path" : " /resource/1" ,
191
191
"body" : { "test" : " test" }
@@ -200,7 +200,7 @@ Not only some part of arguments can use scripts to evaluate it, any value in the
200
200
201
201
For example, the executor name can be the result of the call to another executor:
202
202
203
- ``` JSON
203
+ ``` json
204
204
{
205
205
"$exec" : { "$exec" : " chooseRouter" },
206
206
"$method" : " get" ,
@@ -215,7 +215,7 @@ The script can use results from any part of the script in another part of the sc
215
215
216
216
The previous example where executor name was the result of another script evaluation could be re-written like this:
217
217
218
- ``` JSON
218
+ ``` json
219
219
{
220
220
"router" : { "$exec" : " chooseRouter" },
221
221
"response" : {
@@ -248,7 +248,7 @@ JSONScript interpreters should both try to determine such situations as early as
248
248
249
249
` $if ` instruction can be used to choose the strict that will be evaluated based on some condition:
250
250
251
- ``` JSON
251
+ ``` json
252
252
{
253
253
"$if" : { "$exec" : " checkAvailability" , "$args" : " router1" },
254
254
"$then" : {
@@ -274,7 +274,7 @@ Please note that the interpreter should NOT evaluate both scripts and choose the
274
274
275
275
Scalar values can be used in any place where the script is expected - they evaluate to themselves. We can refactor the script above in this way:
276
276
277
- ``` JSON
277
+ ``` json
278
278
{
279
279
"$exec" : {
280
280
"$if" : { "$exec" : " checkAvailability" , "$args" : " router1" },
@@ -288,7 +288,7 @@ Scalar values can be used in any place where the script is expected - they evalu
288
288
289
289
or using reference:
290
290
291
- ``` JSON
291
+ ``` json
292
292
{
293
293
"router" : {
294
294
"$if" : { "$exec" : " checkAvailability" , "$args" : " router1" },
@@ -310,7 +310,7 @@ or using reference:
310
310
311
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
312
313
- ``` JSON
313
+ ``` json
314
314
{
315
315
"res1" : {
316
316
"$exec" : " router" ,
@@ -332,7 +332,7 @@ The evaluation result will be the same as without `$delay` istruction, but the s
332
332
333
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
334
335
- ``` JSON
335
+ ``` json
336
336
{
337
337
"$exec" : " logger" ,
338
338
"$method" : " resolve" ,
0 commit comments