Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67618

qwebchannel: use Promise for method return values

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.9.4
    • WebChannel
    • None

    Description

      #2 from QTBUG-67592

      in some cases we would like to retrieve the result of a slot synchronously so I propose to wrap the slot invocation in a Promise when there is no callback so that client code may use 'await' 

      function addMethod(methodData) {
      ...
      if (callback) {
                      webChannel.exec({
                          "type": QWebChannelMessageTypes.invokeMethod,
                          "object": object.__id__,
                          "method": methodIdx,
                          "args": args
                      }, function (response) {
                          if (response !== undefined) {
                              var result = object.unwrapQObject(response);
                              (callback)(result);
                          }
                      });
                  } else {
                      var promise = new Promise(function (resolve, reject) {
                          webChannel.exec({
                              "type": QWebChannelMessageTypes.invokeMethod,
                              "object": object.__id__,
                              "method": methodIdx,
                              "args": args
                          }, function (response) {
                              if (response !== undefined) {
                                  var result = object.unwrapQObject(response);
                                  resolve(result);
                              } else {
                                  resolve();
                              }
                          });
                      });
                      return promise;
                  }
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            milianw Milian Wolff
            cassan Claire Cassan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes