I’m trying to use a promise based library (HelloSign) to create an iframe form for the client. However, i’m constantly running into issues dealing with fiber scope every time I have to iterate on it.
If I wrap the first then
callback with bind environment then the emails send but the other part of the code has a hellosign undefined error. Removing bind env makes this undefined error go away but then the emails throw a ‘must always run in a fiber’.
I’ve tried using a callback with Meteor.call
and that doesn’t seem to help any (also wrapping that with bind env doesnt work). If I comment out the Meteor.call
everything is fine (though the email doesn’t send obviously).
Any ideas? I’m about to rip out the Meteor method and start up an Apollo endpoint to get rid of this crazyness.
Meteor.methods({
getIframeURL: function(opts) {
var options = { ... };
// create variable scope
let sigId = null;
const promise = hellosign.signatureRequest.createEmbedded(options)
.then(function(response){
sigId = response.signature_request.signature_request_id;
const signatures = response.signature_request.signatures;
const primarySignatureId = signatures[0].signature_id;
// send message with signature page to each house member
signatures.forEach(function(signature, i) {
hellosign.embedded.getSignUrl(signature.signature_id)
.then(function(res) {
// this throws a "must run in fibers error"
mainServer.call('emailOtherSigners', dataFromRes)
})
.catch((err) => { ... });
});
// continue on with primary applicant signature for iframe url
return hellosign.embedded.getSignUrl(primarySignatureId);
})
.then(function(response){
// use sigId from outer scope here
return response.embedded.sign_url; // primary signer url
})
.catch(...);
return Promise.resolve(promise).await();
}
});