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

"TypeError: object is not a function" when using co with co-monk #6

Open
egeland opened this issue Sep 16, 2015 · 2 comments
Open

"TypeError: object is not a function" when using co with co-monk #6

egeland opened this issue Sep 16, 2015 · 2 comments

Comments

@egeland
Copy link

egeland commented Sep 16, 2015

Hi, I'm still a JS newbie, and very much a n00b to generators, co, monk and co-monk. Probably, I'm making a silly error, but my Google-fu is failing me, so I'm hoping for a pointer in the right direction..

I get a "TypeError: object is not a function" when trying the example in https://github.com/tj/co-monk/tree/67a867016c945ea9cb6cafdc8b5c97788b797ac5 (using co so that yield won't get an error):

})();
  ^
TypeError: object is not a function

Here's my code:

"use strict"; /* jshint node: true, esnext: true */

var monk = require('monk'),
    wrap = require('co-monk'),
    co   = require('co'),
    db   = monk('localhost:27017/test');

var users = wrap(db.get('users'));

co(function *(){
    yield users.remove({});
    // the rest of the code from above
    // ... 
    // finally end generator function
    // and execute co
})();

What am I doing wrong?

Running node v4.0.0, and get the same error with or without --harmony option.

@egeland
Copy link
Author

egeland commented Sep 16, 2015

So I read the source code of co and found co.wrap() and thought "hmm.. let's see if that helps"..

It did - this code works:

"use strict"; /* jshint node: true, esnext: true */

let monk = require('monk'),
    wrap = require('co-monk'),
    co   = require('co'),
    db   = monk('localhost:27017/test');

let users = wrap(db.get('users'));

co.wrap(function *(){
    yield users.remove({});
    yield users.insert({name: 'Test User'});
    var res = yield users.find({});
    console.log(res);
})()
    .then(function () {
        console.log("All done");
        process.exit();
    });

@suhail339
Copy link

It did and this code works : for me also, been stuck for more than 9 hours, many thanks

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