]> git.kaiwu.me - njs.git/commit
Modules: improved handling of results of async handlers.
authorVadim Zhestikov <v.zhestikov@f5.com>
Fri, 25 Jul 2025 00:10:36 +0000 (17:10 -0700)
committerVadimZhestikov <108960056+VadimZhestikov@users.noreply.github.com>
Thu, 6 Nov 2025 23:27:06 +0000 (15:27 -0800)
commit9a5430e6cc409ebc0323ffd937fcb7096fe7fabf
treed17ce6b28e0581a3206e2874a6b1b034fdbbb4f5
parentee8cbf4a05fa7c594ddfb59c3c5de869f8bb0dfd
Modules: improved handling of results of async handlers.

Previously, r.setReturnValue() had to be used when returning a value from async js_set handler.

async function hash(r) {
    let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
    r.setReturnValue(Buffer.from(hash).toString('hex'));
}

Now r.setReturnValue() is not needed:

async function hash(r) {
    let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
    return Buffer.from(hash).toString('hex');
}

Also added promise handling in global qjs code.
nginx/ngx_js.c
nginx/t/js_async.t
nginx/t/js_promise_top_level_await.t [new file with mode: 0644]
nginx/t/stream_js.t