From: Jakub Jirutka Date: Wed, 26 Jan 2022 01:44:18 +0000 (+0100) Subject: Types: added async/await support for TS files. X-Git-Tag: 0.7.3~15 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=6129a9ffbb004baf3439e5bccbaf7d5664b600a2;p=njs.git Types: added async/await support for TS files. Since 0.7.0 async/await support was added. This closes #461 issue on Github. --- diff --git a/test/ts/test.ts b/test/ts/test.ts index a30c5883..0ba55e95 100644 --- a/test/ts/test.ts +++ b/test/ts/test.ts @@ -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 --git a/ts/tsconfig.json b/ts/tsconfig.json index 8cb2218c..a3a5c670 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "module": "es2015", + "module": "ES2017", "lib": [ "ES2015", "ES2016.Array.Include",