exports.handler = async function (event, context, callback) { return new Promise((resolve, reject) => { const cluster = require('cluster') if (cluster.isMaster) { // 创建子进程模拟线上请求的隔离方便global变量的使用保持与FC环境的一致性 const worker = cluster.fork() worker.on('message', (msg) => { // console.log(msg,typeof msg) resolve(msg) }) worker.on('error', error => { // console.log(error) }) worker.on('exit', function (worker, code, signal) { // console.log('Worker %d died with code/signal %s. Restarting worker...', worker.process.pid, signal || code); // cluster.fork(); }) } else { console.log(event, context, callback) // callback() process.on('unhandledRejection', (err) => { // console.log('unhandledRejection', err) // process.send('aaaa') process.exit() }) process.on('uncaughtException', (err) => { // console.log('uncaughtException', err) // process.send('aaaa') process.exit() }) // throw new Error('asxxxxx') process.send({a: 'aaaa', b: 'bbbb'}) process.exit() } }) } exports.handler(1, 2, () => { // console.log('xxxxxxxx') }).then(data => { console.log(data) })