for await()

in src/p5js_playground/index.tsx [146:170]


      for await (const chunk of res) {
        for (const candidate of chunk.candidates ?? []) {
          for (const part of candidate.content.parts ?? []) {
            if (part.thought) {
              playground.setChatState(ChatState.THINKING);
              thought += part.text;
              thinking.innerHTML = await marked.parse(thought);
              thinking.parentElement.classList.remove('hidden');
            } else if (part.text) {
              playground.setChatState(ChatState.CODING);
              newCode += part.text;
              const p5Code = getCode(newCode);

              // Remove the code block, it is available in the Code tab
              const explanation = newCode.replace(
                '```javascript' + p5Code + '```',
                '',
              );

              text.innerHTML = await marked.parse(explanation);
            }
            playground.scrollToTheEnd();
          }
        }
      }