aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpromise/data/promise-all-reject-reject-is-mid.qml
blob: e4bee826fa8b71d02b4b1f84f7e3f8f2c46166d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import QtQuick 2.4

QtObject {
    // TODO!

    property int resolveValue: 5
    property int rejectValue: 10
    property int resultValue: rejectValue
    property bool wasTestSuccessful: false


    property var delayedEvent: Timer {
        interval: 0
        property var handler: null
        onTriggered: {
            if (handler) {
                handler();
            }
        }
    }

    function postEvent(event, value) {
        delayedEvent.handler = function() { event(value) }
        delayedEvent.restart();
    }

    property var promise1: Promise.resolve(resolveValue);
    property int promise2: resolveValue
    property var promise3: Promise.reject(rejectValue)
    property var promise4: new Promise(function (resolve, reject) {
        postEvent(resolve, resolveValue)
    })

    Component.onCompleted: {
        Promise.all([promise1, promise2, promise3, promise4]).then(function() {
            throw new Error("Should never be called")
        }, function(value) {
            if (value !== rejectValue) {
                return;
            }

            wasTestSuccessful = true
        })
    }
}