ArcGIS for Developers

Promise QML Type

(DEPRECATED) Manages asynchronous operations. More...

Import Statement: import ArcGIS.AppFramework.Promises 1.0

Properties

Signals

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 Promise component manages asynchronous computation, allowing for separate processes to continue in parallel. This component must be instantiated before use. This should be used over the Promises component when reliability is more important than speed.

This code sample demonstrates usage of the Promise component. The promise is set to resolve when an image has loaded, and rejected if a timer elapses before the image has been loaded. In both cases, a corresponding message is logged to the console.

Item {
        ColumnLayout {
                anchors {
                        fill: parent
                        margins: 5 * AppFramework.displayScaleFactor
                }

                Image {
                        id : image

                        Layout.fillWidth: true
                        //Layout.fillHeight: 50 * scaleFactor

                        opacity: 0

                        fillMode: Image.PreserveAspectFit
                        asynchronous: true
                        source : "https://lh3.googleusercontent.com/_yimBU8uLUTqQQ9gl5vODqDufdZ_cJEiKnx6O6uNkX6K9lT63MReAWiEonkAVatiPxvWQu7GDs8=s640-h400-e365-rw";
                }
        }

        Timer {
                id: timer
                running: true
                interval: 3000
        }

        Promise {
                // Resolve when the image is ready
                resolveWhen: image.status === Image.Ready

                // Reject when time out.
                rejectWhen: timer.triggered

                onFulfilled:  {
                        console.log("Fulfilled - Image was ready first");
                        // If the timer is reached, the image will not be shown even it is ready.
                        image.opacity = 1;
                }

                onRejected: {
                        console.log("Rejected - Timer got there first");
                }
        }
}

Property Documentation

_promise : object

The promise currently being executed.


[read-only] data : object

Returns the data being passd to the promise.


isFulfilled : bool

Returns true if the promise has been fulfilled. Otherwise, returns false.


isRejected : bool

Returns true if the promise has been rejected. Otherwise, returns false.


isSettled : bool

Returns true if the promise has been either fulfilled or rejected. Otherwise, returns false.


rejectWhen : object

Returns an expression that will act as rejection criteria for the promise.


resolveWhen : object

Returns the condition by which the resolve method will be triggered.


Signal Documentation

fulfilled( object value)

Signal emitted when the promise has been fulfilled.


rejected( object reason)

Signal emitted when the promise has been rejected.


settled( object value)

Signal emitted when the promise is either fulfilled or rejected.


Method Documentation

object _init()

If a promise currently does not exist, creates one with no currently set conditions or triggers.


object _instanceOfSignal(object)

Creates an object that contains the signal being watched for. This method informs the rejectWhen and resolveWhen methods.

The object parameter

The signal that was received.


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 instanceOfPromise(object)

Returns the instance of the promise to be executed.

The object parameter

The promise to be executed.


object reject(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 resolve(value)

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

The value 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.


object then(onFulfilled, object onRejected)

Defines an operation to execute when the promise is either fulfilled or rejected.

The onFulfilled parameter

Course of action if the promise operation is fulfilled.

The onRejected parameter

Course of action if the promise operation is rejected.