プログラム
timeout_test.js
#! /usr/local/bin/node
// timeout_test.js
//
// Feb/08/2023
//
// ---------------------------------------------------------------
'use strict'
// ---------------------------------------------------------------
function first_function(aa,bb)
{
console.error("This is the first function")
console.error("aa = " + aa)
console.error("bb = " + bb)
const sum = aa + bb
console.error("first: sum = " + sum)
}
// ---------------------------------------------------------------
function second_function(aa,bb)
{
console.error("This is the second function")
console.error("aa = " + aa)
console.error("bb = " + bb)
const diff = aa + bb
console.error("second: diff = " + diff)
}
// ---------------------------------------------------------------
function third_function(aa,bb)
{
console.error("This is the third function")
console.error("aa = " + aa)
console.error("bb = " + bb)
const sum = aa + bb
console.error("third: sum = " + sum)
}
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
setTimeout(() => first_function(12,34), 1000)
setTimeout(() => second_function(45,56), 2000)
setTimeout(() => third_function(71,82), 3000)
setTimeout(() => {console.error("*** 終了 ***")}, 4000)
console.error ("*** check bbb ***")
// ---------------------------------------------------------------
実行結果
$ ./timeout_test.js
*** 開始 ***
*** check bbb ***
This is the first function
aa = 12
bb = 34
first: sum = 46
This is the second function
aa = 45
bb = 56
second: diff = 101
This is the third function
aa = 71
bb = 82
third: sum = 153
*** 終了 ***
確認したバージョン
$ node --version
v19.6.0