Using the example from Azure for creating a Durable Function (https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-js-vscode) , I have a working example of the Orchestrator passing each child process a JSON Document that I manually create in the code. However when I attempt to call a function that returns a Promise from within the Orchestrator I get an error as seen in the code below. The sleep function is just mock of the call to the DB that occurs in that the call to the Azure Cosmos DB is wrapped inside a Promise and returns when it has all the documents.
QUESTION -- Is there a means of making the Orchestrator wait for the my sleep function to resolve it's Promise before starting the Chaining Pattern?
/*WORKING EXAMPLE*/
const df = require('durable-functions');
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
let output = [];
context.log("MERGED DOC--START:");
let mergedDoc = {/*SOME MANUALLY CREATED JSON GOES HERE*/};
context.log("MERGED DOC:--EMD");
//let mergedDoc = {};
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-1","data":mergedDoc}));
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-2","data":mergedDoc}));
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-2","data":mergedDoc}));
return output;
});
+++++++++++++++++++++++++++
/*FAILING EXAMPLE*/
const df = require('durable-functions');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
let output = [];
await sleep(5000);
let mergedDoc = {};
/*
ERROR FROM CONSOLE
await sleep(5000);
^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
*/
context.log("MERGED DOC:" + mergedDoc);
//let mergedDoc = {};
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-1","data":mergedDoc}));
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-2","data":mergedDoc}));
output.push(yield context.df.callActivity("E1_SayHello", {"step":"STEP-3","data":mergedDoc}));4
return output;});