ArcGIS for Developers

Promises QML Type

(DEPRECATED) Manages asyncronous operations. More...

Import Statement: import ArcGIS.AppFramework.Promises 1.0

Methods

Detailed Description

This component is in the process of being deprecated, and should not be used. Instead, use the JavaScript implementation for promises.

The Promises component manages asynchronous computation, allowing for separate processes to continue in parallel. This component is a singleton, meaning it does not need to be instantiated. This should be used when speed is more important than reliability, while the Promise component provides tools to better monitor the progress of a promise.

This code sample demonstrates usage of the Promises component. The results of three different tests are printed into the console log: A promise that should resolve, a promise that should be rejected, and a promise linked to emitting a signal.

Item {
    id: item
    signal customSignal(int value)

    function tick() {
        console.log("tick")
        wait(0);
        wait(0);
        wait(0);
    }

    function wait(val)
    {
        console.log("wait", val)
    }

    function test_resolve_value() {
        var fulfilled = false;
        var fulfilledResult = null;
        var rejected = false;

        var promise = Promises.promise();

        promise.then(function(result) {
            fulfilled = true;
            fulfilledResult = result;
        }, function(reason) {
            rejected = true;
            rejectedReason = reason;
        });

        promise.resolve(3);
        compare(fulfilled, false);
        tick();

        compare(fulfilled, true);
        compare(fulfilledResult, 3);
        compare(rejected, false);
    }

    function test_reject_value() {
        var fulfilled = false;
        var fulfilledResult = null;
        var rejected = false;
        var rejectedReason = null;

        var promise = Promises.promise();

        promise.then(function(result) {
            fulfilled = true;
            fulfilledResult = result;
        }, function(reason) {
            rejected = true;
            rejectedReason = reason;
        });

        promise.reject("error");
        compare(fulfilled, false);
        tick();

        compare(fulfilled, false);
        compare(fulfilledResult, null);
        compare(rejected, true);
        compare(rejectedReason, "error");
    }

    function test_resolve_signal() {
        var fulfilled = false;
        var fulfilledResult = [];
        var rejected = false;
        var rejectedReason = null;

        var promise = Promises.promise();

        promise.then(function(result) {
            fulfilled = true;
            fulfilledResult = result;
        }, function(reason) {
            rejected = true;
            rejectedReason = reason;
        });

        promise.resolve(item.customSignal);
        item.customSignal(9);
        compare(fulfilled, false);
        tick();

        compare(fulfilled, true);
        compare(fulfilledResult[0], 9);
        compare(rejected, false);
        compare(rejectedReason, null);

    }

    function compare(val1, val2) {
        console.assert(val1,val2)
    }

    Component.onCompleted: {
        test_resolve_value()
        test_reject_value()
        test_resolve_signal()
    }
}

Method Documentation

object all(promises)

Creates a promise object that will be fulfilled once a supplied array of input promises are fulfilled. If any input promise is rejected, this promise object will also be rejected.

The promises parameter

The promise object fulfilled after all supplied input promises.


object allSettled(promises)

Creates a promise object that will be fulfilled once a supplied array of input promises are fulfilled. If any input promise is rejected, the allSettled promise object will also be rejected. The state of allSettled will not change until all input promises are settled.

The promises parameter

The promise object fulfilled after all supplied input promises.


object clearTimeout(id)

Clears the timeout set by the setTimeout method.

The id parameter

The ID of the timeout to clear.


object instanceOfPromise(promise)

Returns the instance of the promise to be executed.

The promise parameter

The promise to be executed.


object promise()

Returns the promise to be executed.


object rejected(reason)

If the defined reason is fulfilled, the promise is rejected, and the reason is passed to the rejected and settled signals.

The reason parameter

The criteria that the promise can be rejected for.


object resolved(result)

Resolves the promise, passing the given value to the fulfilled and settled signals.

The result parameter

The resolved value of the promise.


object setTimeout(callback, object interval)

Sets a timer for the amount of milliseconds defined by the interval parameter, after which the provided callback function will be called.

The callback parameter

The function to execute when the timer completes.

The interval parameter

The amount of time to set the timeout operation to execute after, in milliseconds.