Skip to content

Instantly share code, notes, and snippets.

@ryanswrt
Created August 14, 2019 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanswrt/93c84d4f2ef11876e4f741f690adce06 to your computer and use it in GitHub Desktop.
Save ryanswrt/93c84d4f2ef11876e4f741f690adce06 to your computer and use it in GitHub Desktop.
const playPauseButton = document.getElementById("play-pause");
let running = false;
const play = () => {
playPauseButton.textContent = "⏸";
// calling the step function will trigger consensus, and therefor the render loop
contract.call(wallet, 'step', BigInt(0), BigInt(1e7), BigInt(0));
running = true;
};
const pause = () => {
playPauseButton.textContent = "▶";
running = false;
};
playPauseButton.addEventListener("click", event => {
if (running) {
pause();
} else {
play();
}
});
// replace the old client.pollConsensus call with
client.pollConsensus({
onRoundEnded: _ => {
contract.fetchAndPopulateMemoryPages().then(_ => {
if(running) {
const results = contract.test(wallet, "render", BigInt(0)).logs[0];
pre.textContent = results;
contract.call(wallet, 'step', BigInt(0), BigInt(1e7), BigInt(0));
}
});
}
});
// kick start by calling play()
play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment