blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.06k stars 415 forks source link

views do not support async `await` #568

Open vitaly opened 3 years ago

vitaly commented 3 years ago

trying to move code from customJs into a dataview view, I get this: await is only valid in async function

blacksmithgu commented 3 years ago

Dataview has explicit support for async/await (and will wrap your code in an implicit async function if you have an await); what is your code? Doing something like

let value = await ...;

works fine in Dataview.

vitaly commented 3 years ago

it works in dataview codeblock, but it doesn't work in a view.

vitaly commented 3 years ago

I had to do this in a view (and it's not exactly correct, ad it still returns a promise and don't make sure all is rendered before returning:

(async () => {
    dv.container = await ad("note", ... 
    ...
})();

and then I use it in a codeblock as dv.view('view path')

blacksmithgu commented 3 years ago

Ah, I understand. Views can also be asynchronous by returning a Promise, they just don't implicitly support await like the main dataview codeblocks do.

Something like

return (async () => {
 ....
})();

I will add direct support for this, the same way normal codeblocks work.