Information Systems



Javascript threading and await

This took me about an hour to figure out this morning.
// this won't work var ard = await -getCheckValue("bsc"+year, '"Total Accounts Receivable"') + await getCheckValue("bsc"+(year-1), '"Total Accounts Receivable"');

putting the minus sign after await runs, but it "awaits" for the negation, not getCheckValue which is what is desired.

The following works.

var ard = -await getCheckValue("bsc"+year, '"Total Accounts Receivable"') + await getCheckValue("bsc"+(year-1), '"Total Accounts Receivable"');

Accounting systems generally need to be run synchronously because they have lots of transactions that depend on previous transactions. In Node.js, they tend to look like:

con = await getConnection();
await con.startTransaction();
try
{
await con.trans1();
await con.trans2();
await con.trans3();
await con.commitTransaction();
}
catch(error)
{
con.reverseTransaction();
}
finally
{
con.releaseConnection();
}