File tree Expand file tree Collapse file tree 2 files changed +30
-12
lines changed Expand file tree Collapse file tree 2 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -149,18 +149,27 @@ export default class RPSBasic {
149
149
* @summary wait :: Number → a → a
150
150
*
151
151
*/
152
- // @rpsAction ({verbName:'wait'})
153
- // wait (ctx:RpsContext,opts:{}, period:number, response?:any) : Promise<any>{
154
- // response = response ? response : ctx.$RESULT;
155
-
156
- // return new Promise(function (resolve,reject) {
157
-
158
- // setTimeout(async function () {
159
- // resolve(response);
160
- // }, period*1000);
161
-
162
- // });
163
- // }
152
+ @rpsAction ( { verbName :'wait' } )
153
+ async wait ( ctx :RpsContext , opts :Object , period :number , response ?:any ) : Promise < any > {
154
+ let isFn = opts [ 'function' ] ;
155
+ response = response ? response : ctx . $RESULT ;
156
+
157
+ function sleep ( res ) {
158
+ let time = period * 1000 ;
159
+ Atomics . wait ( new Int32Array ( new SharedArrayBuffer ( 4 ) ) , 0 , 0 , time ) ;
160
+
161
+ return res ;
162
+ }
163
+
164
+ if ( isFn ) return sleep ;
165
+ else return sleep ( response ) ;
166
+
167
+ // return new Promise(function (resolve,reject) {
168
+ // setTimeout(async function () {
169
+ // resolve(response);
170
+ // }, period*1000);
171
+ // });
172
+ }
164
173
165
174
/**
166
175
* @function stringify
Original file line number Diff line number Diff line change @@ -20,6 +20,15 @@ m.describe('Basic', () => {
20
20
// expect(context.variables['val']).to.be.equals('hello');
21
21
expect ( context . variables [ '$val' ] ) . to . be . equals ( 'hello' ) ;
22
22
23
+ console . log ( 'hello' ) ;
24
+ let fn = await basic . wait ( context , { function :true } , 1 ) ;
25
+ let output = fn ( 'world' ) ;
26
+ console . log ( output ) ;
27
+
28
+ console . log ( await basic . wait ( context , { } , 1 , 'welcome' ) ) ;
29
+ console . log ( await basic . wait ( context , { } , 1 , undefined ) ) ;
30
+ console . log ( await basic . wait ( context , { } , 1 ) ) ;
31
+
23
32
} ) . timeout ( 0 ) ;
24
33
25
34
You can’t perform that action at this time.
0 commit comments