Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle functions that return a promise #18

Open
mmuffins opened this issue Aug 3, 2017 · 0 comments
Open

How to handle functions that return a promise #18

mmuffins opened this issue Aug 3, 2017 · 0 comments

Comments

@mmuffins
Copy link

mmuffins commented Aug 3, 2017

Hi everybody,
I'm trying to retrieve data from a javascript function in an application running on Chromium v53. The function returns a promise which contains an object with the values I'm looking for. The problem I'm having is that I can't resolve the promise.
The following code works fine if I execute it directly in chrome:

var list = app.db.getTracklist('SELECT * FROM Songs', -1);
console.log(list.isLoaded); // returns false
console.log(list.asJSON); // returns blank data

list.whenLoaded().then(function(result){
	console.log(result.isLoaded) //returns true
	console.log(result.asJSON) // returns the data I want
})

What I want to do in my application is the following:

var cmd = new EvaluateCommand{
	ObjectGroup = "console",
	IncludeCommandLineAPI = true,
	DoNotPauseOnExceptionsAndMuteConsole = false,
	ReturnByValue = true,
	Expression = "app.db.getTracklist('SELECT * FROM Songs', -1)"
};

var response = chromeSession.SendAsync(cmd).Result as CommandResponse<EvaluateCommandResponse>;

Console.WriteLine(response.Result.Result.Value);

The last line prints a json object which has the properties isLoaded and asJSON - which are false and blank, respectively. That makes sense since whenLoaded() needs to be called in order to load the data. If I change the expression of the call to "app.db.getTracklist('SELECT * FROM Songs', -1).whenLoaded()", SendAsync() returns a promise (as opposed to the object the promise returns). If I execute synchronous functions I get correct results, so I'm positive that the basic setup is fine.

Does anybody know what I need to do in order to get the data that would be returned in the then() block of the original function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant