Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Wednesday, 31 October 2018 01:47:49 MSK alweiss wrote: > My problem is that services can be one, two … ten etc … so not easy to place > in the callback of the previous subrequest ... > Actually it's not a problem. Here's an example: function authorize(r) { var n = 0; var svcs = ['one

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Ok, got it ! Thanks much Valentin, Maxim and Dmitry for your guidance. I decided to go as the nginx sample (https://www.nginx.com/blog/batching-api-requests-nginx-plus-javascript-module/) with the resp var which is concatened with result of each subrequest : my final_status starts with 403 at init

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
My problem is that services can be one, two … ten etc … so not easy to place in the callback of the previous subrequest ... Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281699,281753#msg-281753 ___ nginx mailing list nginx@nginx.org http:/

Re: Variable scope in javascript module

2018-10-30 Thread Maxim Konovalov
On 31/10/2018 01:27, Valentin V. Bartenev wrote: > On Wednesday, 31 October 2018 00:55:20 MSK you wrote: > [..] > >> However, when i run it, the result is as below : >> The suprising thing is the order it is logged : it seems : as we go for >> async, perhaps both request are started at the same ti

Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Wednesday, 31 October 2018 00:55:20 MSK you wrote: [..] > However, when i run it, the result is as below : > The suprising thing is the order it is logged : it seems : as we go for > async, perhaps both request are started at the same time so each one get a > starting of 403 (no yet updated). C

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Thanks guys, this is a first step. I moved declaration to the top of my script : START SCRIPT * var n = 0; var final_status = 403; var servicesCodes = ['rest','oass']; var requestCount = servicesCodes.length; function authorize(req, res) { req.warn('Variables init ...');

Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Tuesday 30 October 2018 12:58:53 alweiss wrote: > Here is a sample that works with Java but not with njs : > > function my() { > resp = "Start"; > console.log ('Initial resp is ' + resp); > > function done() { > resp += "AndContinue"; > console.log('In loop resp is

Re: Variable scope in javascript module

2018-10-30 Thread Dmitry Volyntsev
On 30.10.2018 19:58, alweiss wrote: Here is a sample that works with Java but not with njs : function my() { resp = "Start"; console.log ('Initial resp is ' + resp); function done() { resp += "AndContinue"; console.log('In loop resp is ' + resp) }

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Here is a sample that works with Java but not with njs : function my() { resp = "Start"; console.log ('Initial resp is ' + resp); function done() { resp += "AndContinue"; console.log('In loop resp is ' + resp) } done(); } resp = 'empty' my(); console.log('End

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Hi Dmitry, thanks for your reply. Here is my code called using js_content authorize; from a location {} I want to say "if at least one subrequest answers HTTP/200, set the final_status to 200 and at then end, return 200" First thing is that i must declare requestCount with var. If i don't, i get

Re: Variable scope in javascript module

2018-10-26 Thread Dmitry Volyntsev
Hi Alex, Can you, please, share your code? You can also try to play with njs code in the command line interface. For example: njs interactive njs 0.2.3 v. -> the properties and prototype methods of v. type console.help() for more information >>function my(){var g = 'init'; console.log(g); (

Variable scope in javascript module

2018-10-25 Thread alweiss
Hi team !, Regarding the sample here : https://www.nginx.com/blog/batching-api-requests-nginx-plus-javascript-module/ I have an issue trying to use JS module : variable hoisting and global/local scope doesn't behave as expected. When i try to reassign the resp variable (as you do after declaring i