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

Server side call to async method returns Promise object, not value. #8367

Closed
robfallows opened this Issue Feb 14, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@robfallows
Contributor

robfallows commented Feb 14, 2017

Refer to this post on the Meteor forums and to @benjamn's comments which follow on.

In a nutshell, a Meteor.call done on the server does not get the return value of an async method. Instead, it gets the Promise object. This is at variance with the expected behaviour.

This has been observed since v1.3, but the reproduction uses v1.4.2.6:

Reproduction:

git clone https://github.com/robfallows/promise-issue promise-issue
cd promise-issue
meteor npm i
meteor

The server's console log shows the result of calling the async method (shows {} - expected "42"):

I20170214-11:23:14.415(0)? The answer to the ultimate question of life, the universe and everything is ... {}

The client browser shows the result of calling the async method from the client (shows "42" as expected):

The answer to the ultimate question of life, the universe and everything is ... 42

@benjamn benjamn self-assigned this Feb 14, 2017

@philcruz

This comment has been minimized.

philcruz commented Feb 21, 2017

I'm seeing this as well.

@Suppen

This comment has been minimized.

Suppen commented Mar 14, 2017

As a workaround, I exported the method function and imported it where I was using it on the server (in another method), then used method.call(this) to get the correct context

@benjamn benjamn added this to the Release 1.4.3.x milestone Mar 16, 2017

benjamn added a commit that referenced this issue Mar 16, 2017

Implement Promise-returning server-side Meteor.{call,apply}Async meth…
…ods.

This is a partial revival of my old #5005 pull request. While we never
came up with a good idiom for Promise-based method stubs on the client,
the server-side changes in this commit should fix #8367.
@benjamn

This comment has been minimized.

Member

benjamn commented Mar 17, 2017

This issue should (finally!) be resolved if you run meteor update --release 1.4.3.3-beta.4 in your application directory, thanks to the commit 0cbd251 referenced above.

benjamn added a commit that referenced this issue Mar 17, 2017

@robfallows

This comment has been minimized.

Contributor

robfallows commented Mar 20, 2017

Works like a charm - thank you @benjamn 👍

@robfallows robfallows closed this Mar 20, 2017

@abernix abernix modified the milestones: Release 1.4.3.x, Release 1.4.3.3 Mar 21, 2017

@abernix abernix added the fixed label Mar 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment