等待我有問題,巴貝爾38年5月8日,等待中的Node.js 我的代碼看起來像:巴貝爾38年8月5日無視Node.js的
/**
* Imports
*/
import {signature} from '../core/antpool';
import log from '../core/logging';
import config from '../config';
import {sendLog as sendEmailLog, EmailTemplate} from '../core/email';
import {rethinkdb, Decorators as DBDecorators} from '../core/db';
import request from 'request';
const tables = {
AntpoolAccount: 'CronAntpoolAccount'
};
class Antpool {
@DBDecorators.table(tables.AntpoolAccount)
static async account(coin) {
var nonce = Date.now();
request.post({
url: config.antpool.baseUrl + '/api/account.htm',
json: true,
form: {
key: config.antpool.key,
nonce: nonce,
signature: signature(nonce),
coin: coin
}
}, function (err, httpResponse, body) {
if (err || httpResponse.statusCode != 201) {
log.error(err, '[CRON][Antpool][Account] Connection problem');
sendEmailLog(EmailTemplate.LOG, {
message: '[CRON][Antpool][Account] Connection problem'
});
return false;
}
var out = JSON.parse(body);
if (out.code != 0) {
log.error(err, '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message);
sendEmailLog(EmailTemplate.LOG, {
message: '[CRON][Antpool][Account] Error response('+out.code+'): '+out.message
});
return false;
}
// Add to database
let obj = {
earn24: out.data.earn24Hours,
earnTot: out.data.earnTotal,
paidOut: out.data.paidOut,
balance: out.data.balance,
createdAt: new Date()
};
// Insert into database
let insert = await this.table.insert(obj).run();
if(insert) {
return true;
} else {
return false;
}
});
}
}
/**
* Exports
*/
export {Antpool};
我所得到的只是錯誤,有問題等待。
SyntaxError: .../antpool.js: Unexpected token (59:22)
// Insert into database
let insert = await this.table.insert(obj).run();
我在想什麼可以解決方案接受等待。這是不是很奇怪,因爲在代碼的其他部分等待運作良好。 不確定究竟是什麼問題,但花了大約兩天才發現問題。
我打電話的腳本有:
/**
* Automatically hook babel into all node requires.
*/
require('babel/register')({
optional: ['es7.asyncFunctions', 'es7.classProperties', 'es7.decorators']
});
/**
* Start application worker.
*/
require('./src/worker');
任何幫助是非常讚賞。
您正在使用的函數中等待「功能(ERR,HttpResponse對象,型)」未署名爲異步 –