Weird asynchronous behaviour in p5.js

In short: I’m making a programming language in p5.js as an exercise, so nothing too serious, however I have incountered a problem which seems to be unique to p5.js . For example, my compiler interprets these 3 successive lines of code “print hey” , “alert”, “print done” and should call IN ORDER the functions “console.log(“hey”)” , “alert()” and "console.log(“done”). However instead I get the alert popup first, then all the console logs together at the end, almost as if p5 was treating the code asynchronously and choosing to perform certain operations before others instead of following the order in which the compiler “gets” them. I tried rewriting the compiler with base javascript and the issue doesn’t exist there, with the same exact code. So why is this? I also tried to fiddle with “async” and “await” but to no avail.

Hi @M1ke,

Depends ond the implementation of console.log which could be implemented to be buffered writer.

— mnse

PS: Don’t call it compiler, but rather interpreter. What’s the difference?

1 Like

Hello @M1ke,

This topic may be of interest:


1 Like

I see, so I guess there is no solution but to use javascript… also for the name: you’re absolutely right, but at the very beginning of this project I had made a custom RAM symulation as well, that stored the program in binary, created from a personalized assembly to which the code was compiled to. Now, hovewer, it’s just an interpreter from my language to js, as you said. Thank you for the answer anyway!