1 | exports.handler = async function (event, context, callback) {
|
2 | return new Promise((resolve, reject) => {
|
3 | const cluster = require('cluster')
|
4 | if (cluster.isMaster) {
|
5 |
|
6 | const worker = cluster.fork()
|
7 | worker.on('message', (msg) => {
|
8 | console.log(msg,typeof msg)
|
9 | resolve(msg)
|
10 | })
|
11 | worker.on('error', error => {
|
12 |
|
13 | })
|
14 | worker.on('exit', function (worker, code, signal) {
|
15 |
|
16 |
|
17 | })
|
18 | } else {
|
19 | console.log(event, context, callback)
|
20 |
|
21 | process.on('unhandledRejection', (err) => {
|
22 | console.log('unhandledRejection', err)
|
23 |
|
24 | process.exit()
|
25 | })
|
26 | process.on('uncaughtException', (err) => {
|
27 | console.log('uncaughtException', err)
|
28 |
|
29 | process.exit()
|
30 | })
|
31 |
|
32 | process.send({a: 'aaaa', b: 'bbbb'})
|
33 | process.exit()
|
34 | }
|
35 | })
|
36 | }
|
37 |
|
38 | exports.handler(1, 2, () => {
|
39 | console.log('xxxxxxxx')
|
40 | }).then(data => {
|
41 | console.log(data)
|
42 | })
|