Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在侦听器上的firebaseRef.on中等待异步值_Javascript_Firebase_Firebase Realtime Database_Async Await - Fatal编程技术网

Javascript 正在侦听器上的firebaseRef.on中等待异步值

Javascript 正在侦听器上的firebaseRef.on中等待异步值,javascript,firebase,firebase-realtime-database,async-await,Javascript,Firebase,Firebase Realtime Database,Async Await,我正在研究如何在调用firebase的.set()方法之前等待从异步函数传递的值!这里有一个不起作用的代码 // main.js firebaseRef.on('value', snap => { if(snap.val()) { otherFirebaseRef.set({ // here i want set the a field with result returned from async function a: (await??)

我正在研究如何在调用firebase的.set()方法之前等待从异步函数传递的值!这里有一个不起作用的代码

// main.js 
firebaseRef.on('value', snap => {
   if(snap.val()) {
     otherFirebaseRef.set({
       // here i want set the a field with result returned from async function 
       a: (await??) asyncFunction()
     })
   }
})
您必须声明函数
async
,并执行以下操作:

firebaseRef.on('value', async snap => {
   if(snap.val()) {
     const theValue = await asyncFunction();
     otherFirebaseRef.set({
       a: theValue 
     })
   } 
})
您必须声明函数
async
,并执行以下操作:

firebaseRef.on('value', async snap => {
   if(snap.val()) {
     const theValue = await asyncFunction();
     otherFirebaseRef.set({
       a: theValue 
     })
   } 
})

@cicciosgamino您好,您有时间查看提议的解决方案吗?@cicciosgamino您好,您有时间查看提议的解决方案吗?