In [1]:
function countTo(number, milliseconds) {
var counter = function() {
console.log(counter._n++);
if (counter._n > number) {
clearInterval(counter._intervalObject);
console.warn("Done!");
}
};
counter._n = 1;
counter._intervalObject = setInterval(counter, milliseconds);
}
countTo(5, 1000);
Out[1]:
IJavascript offers two global definitions to help produce an output asynchronously: $$async$$
and $$done$$()
.
When $$async$$
is set to true
, the IJavascript kernel is instructed not to produce an output. Instead, an output can be produced by calling $$done$$()
.
In [2]:
$$async$$ = true;
console.log("Hello!");
setTimeout(
function() {
$$done$$("And good bye!");
},
1000
);
Out[2]:
It is also possible to produce a graphical output asynchronously, the same way it is done synchronously, with the difference that $$done$$()
has to be called to instruct the IJavascript kernel that the output is ready:
In [3]:
$$async$$ = true;
console.log("Hello!");
setTimeout(
function() {
$$svg$$ = "<svg><circle cx='30px' cy='30px' r='20px'/></svg>";
$$done$$();
},
1000
);
Out[3]: