× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'm not suggesting you can't write typical "business logic" in Javascript, but I'm questioning the wisdom of it and your workarounds demonstrate why IMO. The solution below is like something from a 1980's Windows program before preemptive multitasking was around you had to remember to yield to the OS and I'm sure you don't need me to explain the potential drawbacks. The fixed point function doesn't round properly, as far as I remember, the only safe way to do fixed point maths is to shift the numbers to integers first, either way, it's not as straightforward as you claim. Even if it were, having to wrapper all of your basic maths operations in a function call is error prone and ugly and simply clutters up the program with noise. The benefits of using JS or even Typescript to express your business logic over a language designed specifically for that purpose would have to be significant to outweigh the disadvantages and in it's current state, I don't think they are.


________________________________
From: WEB400 <web400-bounces@xxxxxxxxxxxx> on behalf of Henrik Rützou <hr@xxxxxxxxxxxx>
Sent: 20 March 2018 07:54
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] [EXTERNAL] Re: Rise of Node

Nathan,



It is correct that if you have to loop 10,000,000 times it takes the time
it does, however it is easy to activate the event loop while you loop so
you thereby split’s the loop into intervals of processing:

async function longRun(rid) {

for (let i = 0; i < 10000000; i++) {

cx = Date.now()

if(i % 1000000 == 0) {

console.log(`pid ${process.pid} loop-wait ${rid} -
${i}`)

await asyncEventTrigger(0)

}

}

}



function asyncEventTrigger(delay) {

return new Promise(resolve => {

setTimeout(() => {

resolve('event')

}, delay)

})

}



However (again) there is no need to do this if there is nobody else using
the node instance and thereby competes for resources.



An Await waits by transferring control to the event loop! How on earth
would node else continue to process other code waiting for resources. If
process A has transferred control to process B (that runs your 10,000,000
loop without interruptions) process A waits for the event that process B is
finished with the loop – if process A then fires an SQL command it will
expect to go into a I/O long wait but before it transfers the control to
the event handler so process B may continue. The above shown code will
cause that process A and B (if the run the same code above) will process it
in trunks of 1,000,000 and shift between them for each call to
asyncEventTrigger so the processing would be … A[0] > B[0] > A[1] > B[1] …
A[9] > B[9] … - this is cause by that setTimeout() is a async process and
that is why you can’t use setTimeout() even in normal javascript to pause
the processing – you just pause the processing within the setTimeout()
exactly like a async AJAX call.



Batch example

For each year in 30 years back get each 2 packages of documentation each
about 1.5 MB zipped.

1. Download a zip-file from UN’s homepage

2. Save it in a folder

3. Unzip it

4. Unzip 10 sub-folders in the main unzipped folder

5. Read through each documentation text document and create metadata
Javascript Objects for each document type that defines the whole standard
based on the content (reverse documentation)

by looping through the documentation byte for byte.

- Data-elements

- Composites

- Messages

- Segments

- Codelists 1 + 2

6. Stringify the javascript object into JSON and save the JSON into
files.



Wouldn’t you call that a batch process???

There are many others. E.g. you receive some XML files via FTP you have to
process – some may have a lot of data and may update several tables in you
DB or you have to transfer your daily invoices in trunks to each partner in
XML which requires reading of a queue, reading in tables, creating a XML
document pr. Invoice/partner saving the “package” in the IFS and sending
them with FTP etc.

Or you may want to create binary office documents that includes images or a
lot of other stuff so nodejs is used to many other things than just serving
web-pages and should imho be considered just like java – a VM that runs
javascript to whatever purpose (many that are covered by the 500,000 free
npm’s.)

On Tue, Mar 20, 2018 at 1:24 AM, Nathan Andelin <nandelin@xxxxxxxxx> wrote:

On Mon, Mar 19, 2018 at 10:11 AM, Kelly Cookson <KCookson@xxxxxxxxxxxx>
wrote:

Henrik,

Being a newbie, I am curious. Why would I want to use Node if I’m not
leveraging the event loop with asynchronous programming?


I'm not aware of any way to avoid the event loop in Node.js. It appears
that you can block the cycle from running by coding something like a tight
for-loop (i.e. for i = 1 to 100000000). That would be bad form, of course.
Something like that would block any other scripts from running in that
server. If you ran that in the master process that had forked a set of
child processes, then it would block any inter-process communication that
any applications may rely on.

Perhaps Henrik hadn't put much thought into his message. It wasn't clear
(to me at least) whether his reference to asynchronous programming was in
regard to the new "async" and "await" keywords which make functions appear
to wait for things like DB I/O to occur. They don't actually wait. It's
just a clever way to implement callbacks in Node.js without passing a
reference to callback functions. The actual callback is to the same
function code following the "await" keyword. The function appears to resume
where it left off during an I/O operation, or the like. Several cycles of
the event loop could have actually occurred in between, while the I/O had
actually been passed off to another thread in the thread pool.

I understand in theory that I could have an instance of the event loop
running that processes a batch script instead of handing it off to worker
threads. But that why would I want to do that? I’m genuinely curious
since
I’m still learning and this may be a failure of my imagination.


I'm curious too. Particularly if the "batch script" were performing any DB
I/O. Why would you do that in Node.js?
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing
list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=cXAfKHhr%2BhrRxdxsa1EhPN8yGdr1jF4ynEgCfOkT8GI%3D&reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=%2BY7Qkf5yx8faXNU3vr7eXvsKv%2B4i7h7AoHPCSe%2Fd%2Bgk%3D&reserved=0.




--
Regards,
Henrik Rützou

https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2FpowerEXT.org&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=I7W1F3g4kbYKAe0DBt%2BWPR8v4BwLjQMCwMnvvFVJENk%3D&reserved=0 <https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpowerext.org%2F&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=vjxkFoxDqnWS3T68Xg9QK%2BW1N5ymiW48Qs4M0aslG84%3D&reserved=0>
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.midrange.com%2Fmailman%2Flistinfo%2Fweb400&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=cXAfKHhr%2BhrRxdxsa1EhPN8yGdr1jF4ynEgCfOkT8GI%3D&reserved=0
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Farchive.midrange.com%2Fweb400&data=02%7C01%7C%7C68d5e4aa570c4b66273908d58e2f8fe7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636571257281878657&sdata=%2BY7Qkf5yx8faXNU3vr7eXvsKv%2B4i7h7AoHPCSe%2Fd%2Bgk%3D&reserved=0.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.