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

Can't call event in async mode #26

Open
ruiisidro opened this issue Apr 17, 2018 · 1 comment
Open

Can't call event in async mode #26

ruiisidro opened this issue Apr 17, 2018 · 1 comment

Comments

@ruiisidro
Copy link

I have this scenario:

  1. I've created a collection to log some data.
    When a user posts to this collection I want to call a custom dpd-event where I will call an external service asynchronously. When the external call ends I want to finish up some details in the post data.
//this is the custom dpd-event
//file resources\cloudinarysrv\post.js
var cloudinary = require('cloudinary');

var done = ctx.done          // remember this to end the response (async)
ctx.done = function () { }      // dummy function for autoresponse (sync)

cloudinary.config({
  cloud_name: 'my_cloud_name',
  api_key: 'my_key',
  api_secret: 'my_secret'
});

cloudinary.v2.uploader.upload(ctx.body.ficheiro, function (error, result) {
  if (error) {
    cancel(error.message, 401);
  }
  else {
    console.log("resposta do  cloudinary");
    console.log(JSON.stringify(result));
    setResult(result);
  }
});

As to the collection:

//this is the collection
//resources\exchange\validate.js
var self = this;

if (self.logotipo) {
    dpd.cloudinarysrv.post({ ficheiro: self.logotipo }, function (result, error) {
        if (error) {
            self.logotipo = "upload error image default...";
            self.secureLogotipo = "upload error secured image default...";
        }
        else {
            console.log(JSON.stringify(result));
            console.log("já guardou na cloud e está de volta...");
//this should be get after the external call in dpd-event finishes but the call is not being done asynchronously
            self.logotipo = result.url;
            self.secureLogotipo = result.secure_url;
        }
    });
}
else {
    self.logotipo = "imagem default...";
    self.secureLogotipo = "imagem default segura...";
}

I'm not grasping the async calls concept... can someone help?

@moorthi07
Copy link
Member

moorthi07 commented May 21, 2018

Sorry for delayed reply.

Did you check -
#13

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

2 participants