0

I am trying to wrap a JS Async call with deferred so that I can get the response back. This function is a QtWebEngine function and hence it is asynchronous. However I want to be able to wait for the response.

deferred = $.Deferred();

result = deferred.resolve(host.callMethod());

$.when(result.promise()).done(function(value)
{
    alert(value)
});

I was expecting that the value to the call back will be the output of the Host.callMethod.

Your help is appreciated.

GillesC
  • 10,647
  • 3
  • 40
  • 55
  • How is `host.callMethod()` dealing with async? Is it returning a promise or taking a callback as an argument? – sp00m May 04 '17 at 12:28
  • Try `host.callMethod(function(deferred.resolve){ return deferred.promise(); })` OR `host.callMethod(function(data){ deferred.resolve(data); return deferred.promise(); })` – Sumit Ridhal May 04 '17 at 12:53
  • Thanks for the help guys. The hostMethod returns a promise. It worked with deferred.promise :) – Arvindnat111 Jul 27 '17 at 20:00

0 Answers0