
import {ThreadPool} from "./ThreadPool.js";
const pool = new ThreadPool(5);

let data = { name: '你好' }

// 异步任务
pool.submitAsync(end => {
      setTimeout(() => {
            console.log("任务一开始" + new Date().getTime());
            let num = 0;
            while (true) {
                  num++;
                  if (num > 100000000) {
                        console.log("任务一结束" + new Date().getTime());
                        break;
                  }
            }
            end();
      }, 1000);
});

//异步任务+入参
pool.submitAsync((end, data1) => {
      setTimeout(() => {
            let num = 0;
            console.log("任务二开始" + new Date().getTime() + ",data=" + JSON.stringify(data1));
            while (true) {
                  num++;
                  if (num > 100000000) {
                        console.log("任务二结束" + new Date().getTime());
                        break;
                  }
            }
            end();
      }, 1000);
}, data);

//同步任务
pool.submit(data1 => {

      console.log("任务一开始" + new Date().getTime() + ",data" + JSON.stringify(data1));
      let num = 0;
      while (true) {
            num++;
            if (num > 100000000) {
                  console.log("任务一结束" + new Date().getTime());
                  break;
            }
      }

}, data);

//同步任务+入参
pool.submit(data1 => {
      console.log("任务二开始" + new Date().getTime() + ",data" + JSON.stringify(data1));
      let num = 0;
      while (true) {
            num++;
            if (num > 100000000) {
                  console.log("任务二结束" + new Date().getTime());
                  break;
            }
      }
}, data);
