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

Fix return output binding logic #264

Merged
merged 11 commits into from
Dec 2, 2019
4 changes: 3 additions & 1 deletion scripts/generateProtos.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function generateProtos() {
.catch(err => console.log(`Could not compile to JavaScript: ${err}`));

// Don't generate with Node.js v12 until resolved: https://github.com/protobufjs/protobuf.js/issues/1275
if (!process.version.startsWith("v12")) {
if (process.version.startsWith("v12") && process.platform === 'win32') {
console.warn("Warning! Could not compile to TypeScript for Node.js 12 and Windows OS. Do not change public interfaces.");
} else {
genTs(allFiles)
.then(data => console.log("Compiled to TypeScript."))
.catch(err => console.log(`Could not compile to TypeScript: ${err}`));
Expand Down
23 changes: 16 additions & 7 deletions src/WorkerChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ export class WorkerChannel implements IWorkerChannel {
// Validate version
let version = process.version;
if (this._v1WorkerBehavior) {
if (version.startsWith("v12."))
{
if (version.startsWith("v12.")) {
systemWarn("The Node.js version you are using (" + version + ") is not fully supported with Azure Functions V2. We recommend using one the following major versions: 8, 10.");
}
} else {
if (version.startsWith("v8."))
{
if (version.startsWith("v8.")) {
let msg = "Incompatible Node.js version. The version you are using (" + version + ") is not supported with Azure Functions V3. Please use one of the following major versions: 10, 12.";
systemError(msg);
throw msg;
Expand Down Expand Up @@ -192,10 +190,22 @@ export class WorkerChannel implements IWorkerChannel {
response.returnValue = toTypedData(result.return);
} else {
let returnBinding = info.getReturnBinding();
response.returnValue = returnBinding ? returnBinding.converter(result.return) : toTypedData(result.return);
// $return binding is found: return result data to $return binding
if (returnBinding) {
response.returnValue = returnBinding.converter(result.return);
// $return binding is not found: read result as object of outputs
} else if (result.return) {
response.outputData = Object.keys(info.outputBindings)
.filter(key => result.return[key] !== undefined)
.map(key => <rpc.IParameterBinding>{
name: key,
data: info.outputBindings[key].converter(result.return[key])
});
}
}
}
if (result.bindings) {
// Data from return supersedes data from context.bindings
if (result.bindings && !response.outputData) {
response.outputData = Object.keys(info.outputBindings)
.filter(key => result.bindings[key] !== undefined)
.map(key => <rpc.IParameterBinding>{
Expand All @@ -207,7 +217,6 @@ export class WorkerChannel implements IWorkerChannel {
} catch (e) {
response.result = this.getStatus(e)
}

this._eventStream.write({
requestId: requestId,
invocationResponse: response
Expand Down
Loading