luciotato / waitfor

Sequential programming for node.js, end of callback hell / pyramid of doom
MIT License
531 stars 29 forks source link

wait.for outputting [object Object] #26

Closed 0xdeafcafe closed 9 years ago

0xdeafcafe commented 9 years ago

When using the library, it hits the following line: (where graph.get is from the fbgraph npm package)

var result = wait.for(graph.get, url, { });

It just outputs [object Object] to the console, and prematurely ends execution of my application. The full source code is as follows:

var program = require('commander');
var graph = require('fbgraph');
var wait = require('wait.for');

program
    .version('0.0.1')
    .option('-i, --id [id]', '(required) facebook profile id of the user to target')
    .option('-t, --token [token]', '(required) facebook access_token used to do the abuse from')
    .option('-p, --pages [count]', '(defaults to 1000) number of pages of likes to look through')
    .parse(process.argv);

if (program.id == undefined && program.token == undefined && program.pages == undefined) {
    program.help();
    process.exit(1);
}

if (program.id == undefined || program.token == undefined) {
    console.error("ERR: It's required to specify both an id and a token. Type `fb-spam -h` for more information.\n");
    process.exit(1);
}

var user_id = program.id;
var access_token = program.token;
var pages = program.pages;
if (pages == undefined) pages = 1;

graph.setAccessToken(access_token);

wait.launchFiber(function () {
    var feeds = [
        "feed",
        "photos",
        "photos/uploaded",
        "videos",
        "videos/uploaded",
        "albums"
    ];
    var ids = [ ];

    // Gets Ids
    for (var i = 0; i < feeds.length; i++) {
        var feed = feeds[i];
        var url = user_id + "/" + feed + "?fields=comments.fields(id),id";

        console.log("xox");
        var result = wait.for(graph.get, url, { });
        console.log("x");
    }
});

And the full console output is:

PS C:\Users\Alex\Source\Personal\fb-spam> node .\app.js -i xbdm.xex -t [token, redacted]
xox

[object Object]
luciotato commented 9 years ago

try

var result = wait.forMethod(graph,'get', url, { });
0xdeafcafe commented 9 years ago

Yeah, I tried that also. Exactly the same output.

luciotato commented 9 years ago

1) if you do:

 graph.get (url, { }, function(err,data){
        console.log(err,data);
 });

what do you get?

2) what's with the "{ }" ? try also:

 graph.get (url, function(err,data){
        console.log(err,data);
 });

I'm not familiar with the fbgraph lib, but wait.for does nothing especial but calling the function just adding a parameter : callback(err,data)

wait.forMethod does the same, but bind the called function (sets "this") with the first parameter, effectively calling a "method".

0xdeafcafe commented 9 years ago

Ah yes, get was returning an error and that was just returning object. Fixed my logic calling get, and it's working fine. Thanks!