JSFiddle - React, Tailwind, and code Playground

by Kenneth Kin Lum

CSS

body {
    font: 12px Consolas, Monaco, monospace;
}

JavaScript

var promise = new Promise(function (honor_with, not_keep) {

    var timerID = setInterval(function () {

        var i = Math.round(Math.random() * 10000);

        if (i > 9000) {
            honor_with(i);
            clearInterval(timerID);
        } else if (i < 1000) {
            not_keep();
            clearInterval(timerID);
        }

        $("body").append("<div>Person B: I am thinking or not doing anything, at " + (new Date()).toLocaleTimeString() + "</div>");

    }, 1000);

});

promise.then(function (foo) {
    $("body").append("<div>Person A: wow I just know that the promise was kept, with the data being " + foo + ", at " + (new Date()).toLocaleTimeString() + "</div>");
});

promise.catch (function () {
    $("body").append("<div>Person A: wow I just know that the promise was not kept, at " + (new Date()).toLocaleTimeString() + "</div>");
});