Running Stockfish commands

I would like to use the chess program stockfish and found this nice notebook which shows how to send commands to a web worker running stockfish: Hello, Stockfish / Arcticio / Observable

When clicking on a button an onclick() callback function is executing a command like ask(stockfish, “uci”).
How can I call this command in the regular code block. If I create a new cell with ask(stockfish, "uci") , it creates an infinite loop of calls.
But I would like to call it just once. I guess I am missing some basics about async functions and promises.

The cell ask() references both mutable trigger and trigger. When it runs and updates mutable trigger, it automatically invalidates itself. This doesn’t cause problems with the existing buttons because there the function is only run via a user interaction.

A simplified example of a cell that invalidates itself every three seconds:

mutable foo = true
  foo; // reference the mutable's value.
  let n = 0;
  while(true) {
    if(n >= 3) mutable foo = true; // causes "foo" to update - the value doesn't matter
    yield n++;
    await Promises.delay(1000);
1 Like