Template result is only flushed after several seconds

I’m running into the issue that both Templater and Templates plugins don’t seem to flush the new content immediately to the file.

Even weirder, I can see their result on the editor right away, but when I read the file from my plugin I get the content before the template was applied. If I make the plugin wait for 5-10 seconds then I do get the newer content, but it’s too long of a wait.

Here is a sample snippet:

// Insert template into currently active note
await (this.app as any).internalPlugins?.plugins["templates"]?.instance.insertTemplate(template_file);

// Without this line I get contents before applying template.
await (new Promise(resolve => setTimeout(resolve, 5000)));

// Log contents of the note to console
console.log(await this.app.vault.read(this.app.workspace.activeEditor?.file!));