1

I'm calling an algorithm, which has this standard format:

var input = "x";

Algorithmia.client("API")
       .algo("algorithm name")
       .pipe(input)
       .then(function (output) {
         console.log(output);
       });

It works well, but I can't seem to figure out how to return the output to a global variable.

I'm fairly new to programming and haven't done anything with Promises yet (which from what I understand, this is utilizing), so any help would be much appreciated.

Jack
  • 23
  • 1
  • 8
  • In a nutshell: you cannot. Put your code into the `then` callback to do your work there. – deceze Feb 06 '17 at 14:04
  • You just set it: `var outputGlobal = null; Algorithmia.client(...).pipe(...).then(function(output){outputGlobal = output;});` The better solution though would be to pass output directly to the function that will handle the output, so you don't actually have a global state. And keep in mind the global output var will only have the value After the `then()` function has run. – Shilly Feb 06 '17 at 14:04

0 Answers0