Smart object window listener in Photoshop scripting - is it possible?

function waitForSmartObjectClosure() {
        if (!smartObjectClosed) {
            checkSmartObjectClosure();
            $.sleep(1000); // Wait for 1 second before checking again
            waitForSmartObjectClosure();
        } else {
            callback();
        }
    }

JavaScript doesn’t have a sleep method due to its asynchronous nature. Whilst you could replicate this approach using setTimeout and checking if app.documents contains the smart object document it would be more elegant to use an event listener for the document close event and then in the callback function compare the document id to that of your smart object document.