[njs] Types: added async/await support for TS files.

Dmitry Volyntsev xeioex at nginx.com
Thu Jan 27 13:03:25 UTC 2022


details:   https://hg.nginx.org/njs/rev/403f7fe07fe8
branches:  
changeset: 1820:403f7fe07fe8
user:      Jakub Jirutka <jakub at jirutka.cz>
date:      Wed Jan 26 02:44:18 2022 +0100
description:
Types: added async/await support for TS files.

Since 0.7.0 async/await support was added.

This closes #461 issue on Github.

diffstat:

 test/ts/test.ts  |  5 ++++-
 ts/tsconfig.json |  2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diffs (41 lines):

diff -r 328bb7c20642 -r 403f7fe07fe8 test/ts/test.ts
--- a/test/ts/test.ts	Wed Jan 26 17:24:57 2022 +0000
+++ b/test/ts/test.ts	Wed Jan 26 02:44:18 2022 +0100
@@ -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});
diff -r 328bb7c20642 -r 403f7fe07fe8 ts/tsconfig.json
--- a/ts/tsconfig.json	Wed Jan 26 17:24:57 2022 +0000
+++ b/ts/tsconfig.json	Wed Jan 26 02:44:18 2022 +0100
@@ -1,7 +1,7 @@
 {
     "compilerOptions": {
         "target": "es5",
-        "module": "es2015",
+        "module": "ES2017",
         "lib": [
             "ES2015",
             "ES2016.Array.Include",



More information about the nginx-devel mailing list