I am trying to fetch a file into a synchronous class. But I cannot solve a problem that appeared: I need to get a return value of a function and store it into a variable, although I do not know when the promise will be fulfilled. Can someone explain a way to get my body?
function fetchSource(name: string): string { let source: string | null; getFileContents(name).then((response) => source = response); if (!source) { // <-- here we do not know at runtime what the value of this varaible is throw new Error("Cannot fetch shader source file " + name +"."); } return source;}