1. Home
  2. Docs
  3. Manual
  4. Playbook
  5. Command list
  6. CustomCommand component

CustomCommand component

Provides a reference example for custom commands for developers to reference and develop.
Its reference example:
https://github.com/aoyiduo/woterm/blob/main/private/playbooks/test/TestCustomCommand.qml

Timer {
   id: timer
}

function sleep(ms) {
   return new Promise(function(resolve, reject){
       timer.interval = ms
       timer.repeat = false
       timer.running = false

       let fnTriggered = function() {
           timer.triggered.disconnect(fnTriggered)
           Qt.callLater(resolve)
       }
       timer.triggered.connect(fnTriggered)
       timer.start()
    })
}

function assertEqual(x, y) {
    return new Promise(function(resolve, reject) {
        if(x === y) {
           Qt.callLater(resolve, "Yes, it's equal.")
        }else{
           Qt.callLater(reject, "No, it's not equal.")
        }
    });
}

asyncGenerator(function *(){
    for(let i = 0; i < 10; i++) {
        let a = Math.random() * 100;
        let b = Math.random() * 100;
        let x = Math.floor(a % 2)
        let y = Math.floor(b % 2)
        Playbook.log("loop i=", i, x, y)
        yield assertEqual(x, y).then(function(result){
            Playbook.log("assertResult.then", result)
        }).catch(function(err){
            Playbook.log("assertResult.catch", err)
        })
        yield sleep(1000)
    }
})()