技术使用: React,Redux,Saga如何在第二次函数调用后立即访问数据?firstFunction继续执行其余的代码。我尝试了async/await,但不起作用。
firstFunction (()=>{
secondFunctionAPI() //using Redux and Saga
// Here I want to use the data from the response of secondFunction().
more code...
more code..
})
最近我开始学习如何在firebase中读写网页,但在我的登录表单中,当我按下submit时,它会显示输入是错误的,但当我再次按submit时,它会工作并显示我已登录。
我记录(console.log)正在读取的内容,并意识到在第一次单击时,它返回null,但当我再次按下时,它将返回正确的数据。我试着使用"async“和"await",但问题仍然存在。
以下是我的Javascript代码:
async function read(dbRef){
let ret = null;
dbRef.on('value', function(snapshot)
尝试使用async和await在nodejs中执行http请求,但得到了错误。有什么想法吗?Thx
got response:
undefined
/home/tom/learn/node/node_modules/node-rest-client/lib/node-rest-client.js:539
callback(parsedData,res);
^
TypeError: callback is not a function
at /home/tom/learn/node/node_modules/node-rest-clie
每当我试图从密码或奈米(新库)中生成随机密钥时,它只会返回对象承诺
async function createCode(length){
if(!length){
return nanoid;
} else {
return nanoid(length);
}
}
// another one for example
async function createCode(){
return await crypto.randomBytes(64).toString('hex');
}
如何更改data在asyncCall()中的值,并将其设置为承诺的解析值,即b。
我想要的是asyncCall()将返回b。但是所发生的事情是,asyncCall()返回一个允诺对象。
function resolveAfter2Seconds(data) {
return new Promise(resolve => {
resolve(data);
});
}
async function asyncCall() {
let data = "a";
var result = await resolveAfter2Seconds("
我尝试在node js中使用回调函数,所以我像这样传递变量和回调函数: if(true){
await this.serialNumber(customer, async serial => {
console.log(serial); // it's log 43435543
});
// I need to use that serial out of the scope of that function by passing it to this new function
await this.storeinDB(customer, serial);
}
// thi