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

storing deferred results in a hash #14

Closed
jpmoodlerooms opened this issue Jul 27, 2012 · 1 comment
Closed

storing deferred results in a hash #14

jpmoodlerooms opened this issue Jul 27, 2012 · 1 comment

Comments

@jpmoodlerooms
Copy link

When I try to store the results of a deferred call in a hash, I'm getting the value of the deferred object rather than the result it points to. Here's a simple program to demonstrate what's happening:

(function() {
    var fs = require("fs");
    var asyncblock = require("asyncblock");

    if (asyncblock.enableTransform(module)) {
        return;
    }

    asyncblock(function() {
        var synced = fs.readFile(__filename, 'utf8').sync();
        var deferred = fs.readFile(__filename, 'utf8').defer();
        var hash = {};
        hash.sync = synced;    // this works just fine
        hash.defer = deferred; // this doesn't work
        console.log(hash);

        console.log(deferred); // this works just fine too

        var d = deferred;      // using an intermediate works
        hash.defer = d;
        console.log(hash);
    });
})();

Here's the suspicious output from the hash assignment:


  defer: 
   { _flow: 
      { _parallelCount: 1,
        _parallelFinished: 0,
        _fiber: [Object],
        _taskQueue: [],
        _forceWait: false,
        _light: true,
        _finishedTasks: {},
        errorCallback: null,
        taskTimeout: null,
        timeoutIsError: null,
        _originalError: [Error],
        _parentFlow: undefined,
        _isGenerator: false,
        maxParallel: 0,
        firstArgIsError: true },
     _key: '__defaultkey__',
     _result: null,
     _resultObtained: false } }
scriby pushed a commit that referenced this issue Jul 28, 2012
scriby pushed a commit that referenced this issue Jul 28, 2012
Fix issue #14
@scriby
Copy link
Owner

scriby commented Jul 28, 2012

Fixed in 2.1.2

@scriby scriby closed this as completed Jul 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants