0

I'm using a fluture to handle the response from an AWS service request.

I get the expected response using a callback or a Promise wrapped around the callback. When I try to use a fluture, looks like I am getting back a regurgitation of the request. Gotta be something stoopid... (again)

const Rekognition = require ('aws-sdk/clients/rekognition');
const rekognition = new Rekognition ({
    region: 'us-east-1'
});

const fs = require ('fs');
const Future = require ('fluture');


const imageBytes = fs.readFileSync ('../data/image.jpg');


const params = {
    Image: {
        Bytes: imageBytes
    }
};

const detectText = Future((rej, res) =>
    rekognition.detectText(params, (err, data) => err ? rej(err) : res(data)));

detectText.fork(console.error, console.log);

Expected results: { TextDetections: [ { DetectedText: 'text1', Type: 'LINE', Id: 0, Confidence: 98.7948989868164, Geometry: [Object] }, { DetectedText: 'text2',...

Actual results: c5GeDWkmkn3ZpFJK/UszSxBOCN2AR7Gs0uqtHlSDuGHX+EnuakC43xxqN6ABWY/e+lRiOaNrg+UWKqGAHfii0bXZv...

bbarrington
  • 115
  • 7
  • I'm not sure exactly from your description what the question is, but I can spot one mistake in there: you're not returning a cancellation function into `Future()`. You're probably better off using `detectText = Future.node(done => rekognition.detectText(params, done))`, which doesn't need a cancellation function. – Avaq Jun 05 '19 at 15:10
  • I think if I enclose the body of that function in braces, it will achieve the desired result. I haven't had time to test this yet on this specific piece of code, but I noticed I had problems on some other stuff I was doing without the braces. IOW, the code would look like this: ```const detectText = Future((rej, res) => { rekognition.detectText(params, (err, data) => err ? rej(err) : res(data))}); ``` – bbarrington Jun 06 '19 at 22:18

0 Answers0