Gulp [4.0.2] 异步函数完成时挂起,即使回调已完成
Gulp [4.0.2] hangs when async function is completed even though callback is completed
我有一个 gulp 任务在完成后挂起。
运行 --verbose
我的命令告诉我它完成了 运行,但它没有退出进程
// ./gulpfile.js/precon/index.js
const { preconMoveFile, preconExcelToMysql } = require('../../src/lib/preCon')
module.exports = async done => {
try {
await preconMoveFile()
await preconExcelToMysql()
done()
// return <-- doesnt work either per comment
} catch (e) {
throw e
}
}
下面是命令行输出,请原谅我的调试日志输出
C:\Users\ALilland\Documents\macros\experiments\forecast-scraper>set NODE_ENV=development& gulp precon --verbose
[12:33:57] Using gulpfile ~\Documents\macros\experiments\forecast-scraper\gulpfile.js
[12:33:57] Starting 'precon'...
[2019-07-30T19:33:57.264Z] DEBUG - [preCon.preconMoveFile] existing ./src/tmp/precon.xlsx removed
[2019-07-30T19:33:57.333Z] DEBUG - [preCon.preconMoveFile] copied new file to ./src/tmp/precon.xlsx
[2019-07-30T19:33:58.965Z] INFO - [initialize.db.caePreconForecast] created caePreconForecast
[2019-07-30T19:33:59.012Z] DEBUG - [preCon.preconExcelToMysql] added rows to db
[12:34:00] Finished 'precon' after 3.24 s
我尝试了 docs with no success, and also tried several of the options here 中显示的几个选项但没有成功
我也曾尝试调用 process.exit(0)
,但这会产生文档提到的 Did you forget to signal async completion?
警告
编辑:
我还应该注意我的根 index.js 文件需要 precon
任务
// ./gulpfile.js/index.js
exports.default = require('./default')
exports.precon = require('./precon')
挂起不是由 gulp 引起的,后台进程仍在 运行 阻止 gulp 关闭
罪魁祸首是打开的 mysql 池连接
const mysql = require('mysql')
const params = require('../config/mysql')
const db = mysql.createPool(params)
db.end() // <-- running this after each task resolves the issue
我有一个 gulp 任务在完成后挂起。
运行 --verbose
我的命令告诉我它完成了 运行,但它没有退出进程
// ./gulpfile.js/precon/index.js
const { preconMoveFile, preconExcelToMysql } = require('../../src/lib/preCon')
module.exports = async done => {
try {
await preconMoveFile()
await preconExcelToMysql()
done()
// return <-- doesnt work either per comment
} catch (e) {
throw e
}
}
下面是命令行输出,请原谅我的调试日志输出
C:\Users\ALilland\Documents\macros\experiments\forecast-scraper>set NODE_ENV=development& gulp precon --verbose
[12:33:57] Using gulpfile ~\Documents\macros\experiments\forecast-scraper\gulpfile.js
[12:33:57] Starting 'precon'...
[2019-07-30T19:33:57.264Z] DEBUG - [preCon.preconMoveFile] existing ./src/tmp/precon.xlsx removed
[2019-07-30T19:33:57.333Z] DEBUG - [preCon.preconMoveFile] copied new file to ./src/tmp/precon.xlsx
[2019-07-30T19:33:58.965Z] INFO - [initialize.db.caePreconForecast] created caePreconForecast
[2019-07-30T19:33:59.012Z] DEBUG - [preCon.preconExcelToMysql] added rows to db
[12:34:00] Finished 'precon' after 3.24 s
我尝试了 docs with no success, and also tried several of the options here 中显示的几个选项但没有成功
我也曾尝试调用 process.exit(0)
,但这会产生文档提到的 Did you forget to signal async completion?
警告
编辑:
我还应该注意我的根 index.js 文件需要 precon
任务
// ./gulpfile.js/index.js
exports.default = require('./default')
exports.precon = require('./precon')
挂起不是由 gulp 引起的,后台进程仍在 运行 阻止 gulp 关闭
罪魁祸首是打开的 mysql 池连接
const mysql = require('mysql')
const params = require('../config/mysql')
const db = mysql.createPool(params)
db.end() // <-- running this after each task resolves the issue