-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break type of mermaid.render in v10 #3577
Comments
Hi Just to clarify something, are you saying this will also not work as expected? const [d1, d2] = await Promise.all([
renderDiagram1(),
renderDiagram2(),
]) Because even with async/await, intuitively it's code I would use to optimize performances. |
Hi, I just wanted to give some feedback as I ran into this issue.
Based on the documentation and method signature, it was not clear to me that I see two approaches that would have helped me:
I ended up wrapping the Mermaid function makeSequential(asyncFn) {
const queue = []
let inProgress = false
async function processQueue() {
if (inProgress)
return
inProgress = true
while (queue.length > 0) {
const { args, resolve, reject } = queue.shift()
try {
const result = await asyncFn(...args)
resolve(result)
} catch (error) {
reject(error)
}
}
inProgress = false
}
return function (...args) {
return new Promise((resolve, reject) => {
queue.push({ args, resolve, reject })
processQueue()
})
}
}
const renderMermaid = makeSequential((mermaidAPI, id, text) => mermaidAPI.render(id, text)) I don't know the internals of Mermaid, but I imagine something similar could be used internally in the library to completely hide this complexity from the API consumer. With this approach the consumer would not need to know that |
Describe the bug
Context: With the upcoming v10, mermaidAPI.render is async.
Sid:
The main problem is that mermaid can't be run concurrently.
So if someone calls render multiple times in a loop (or in succession) without await, everything falls apart. (As witnessed in E2E tests)
When we provide the option for callback, people might not use await and only pass the callback. Or just leave everything as is and simply upgrade to v10.
If anyone is upgrading to v10, it needs to be clear that their code will break if they don't use await.
The issue is that the breaks might not be obvious or consistent. There might not be any errors, either.
But if we break the function signature, then it's explicit. They know when upgrading to v10 that something needs to be done wherever they are calling render.
Knsv:
That makes sense. I could see how a clear call in a diagram could mess things up.
Then perhaps we also change init to run and handle unknown diagram as an error diagram with that as a message, instead of a flowchart
The text was updated successfully, but these errors were encountered: