export values from async function

Issue

This Content is from Stack Overflow. Question asked by Pratheek Reddy

in test.js, I have some callback that resolves “a” value. then further the “a” value is exported at the end of the file

//test.js
let fun = async ()=>{
let a
    await setTimeout(()=>{a = 10}, 100)
    return a
}

let a  
fun().then(val=>{a=val})
export default a

when im trying to import a value in test1.js, im getting a as undefiner

test1.js
import a from './test.js'

console.log(a) //undefined



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?