]> git.kaiwu.me - njs.git/commitdiff
Types: added async/await support for TS files.
authorJakub Jirutka <jakub@jirutka.cz>
Wed, 26 Jan 2022 01:44:18 +0000 (02:44 +0100)
committerJakub Jirutka <jakub@jirutka.cz>
Wed, 26 Jan 2022 01:44:18 +0000 (02:44 +0100)
Since 0.7.0 async/await support was added.

This closes #461 issue on Github.

test/ts/test.ts
ts/tsconfig.json

index a30c58831be7efe3f3227e1cd10c878eb51894f1..0ba55e95676f265f837086c92915181c35b8d5a3 100644 (file)
@@ -2,7 +2,7 @@ import fs from 'fs';
 import qs from 'querystring';
 import cr from 'crypto';
 
-function http_module(r: NginxHTTPRequest) {
+async function http_module(r: NginxHTTPRequest) {
     var bs: NjsByteString;
     var s: string;
     var vod: void;
@@ -68,6 +68,7 @@ function http_module(r: NginxHTTPRequest) {
     // Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply => r.return(reply.status));
     r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
                                         JSON.stringify(JSON.parse(reply.responseBody ?? ''))));
+    let body = await r.subrequest('/p/sub7');
 
     // r.requestText
     r.requestText == 'a';
@@ -94,6 +95,8 @@ function http_module(r: NginxHTTPRequest) {
     .then(body => r.return(200, body))
     .catch(e => r.return(501, e.message))
 
+    let response = await ngx.fetch('http://nginx.org/');
+
     // js_body_filter
     r.sendBuffer(Buffer.from("xxx"), {last:true});
     r.sendBuffer("xxx", {flush: true});
index 8cb2218c8298a28bba327762e75f76b64f5e2a64..a3a5c670f7bcadbce6a69535dea546ff21decb4e 100644 (file)
@@ -1,7 +1,7 @@
 {
     "compilerOptions": {
         "target": "es5",
-        "module": "es2015",
+        "module": "ES2017",
         "lib": [
             "ES2015",
             "ES2016.Array.Include",