Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Cannot read property 'then' of undefined when create PromiseList #77

Closed
stoyanmkd opened this issue Apr 10, 2017 · 1 comment
Closed

Comments

@stoyanmkd
Copy link

Hello, I'm newbie in Comb and I have the following problem with PromiseLists. I follow the documentation for PromiseLists and create following code:

var comb = require('comb');
    fs = require('fs');

function readFiles(){
	var files = comb.argsToArray(arguments).map(function(file){
		return fs.readFile(file);
	});
	return new comb.PromiseList(files, true).promise();
	
}

readFiles("1.txt", "2.txt", "3.txt").then(function(files){
	files.forEach(function(data){
		console.log(data);
	});
}, errorHandler);

When I run it, I got error:

/opt/dbtest/test2/node_modules/comb/lib/promise.js:529
            promise.then(
                   ^

TypeError: Cannot read property 'then' of undefined
    at wrapper.__addPromise (/opt/dbtest/test2/node_modules/comb/lib/promise.js:529:20)
    at forEach (/opt/dbtest/test2/node_modules/comb/lib/base/array.js:191:18)
    at wrapper.constructor (/opt/dbtest/test2/node_modules/comb/lib/promise.js:515:17)
    at spreadArgs (/opt/dbtest/test2/node_modules/comb/lib/base/functions.js:30:17)
    at new wrapper (/opt/dbtest/test2/node_modules/comb/lib/define.js:77:19)
    at spreadArgs (/opt/dbtest/test2/node_modules/comb/lib/base/functions.js:30:17)
    at wrapper.defineConstructor (/opt/dbtest/test2/node_modules/comb/lib/define.js:329:9)
    at readFiles (/opt/dbtest/test2/app.js:10:9)
    at Object.<anonymous> (/opt/dbtest/test2/app.js:14:1)
    at Module._compile (module.js:570:32)

I'm running it on Node 6.10.2, the version of Comb is 1.0.1

Thanks,
Stoyan

@dustinsmith1024
Copy link
Contributor

I think you need to turn fs.readFile into a comb Promise. The examples all build off of each so, you can find the readFile non-standard lib one in at the top of the Promises doc. Try swapping the fs version out for the one in the docs.

Also, we don't run comb on node 6 internally so you might run into some bugs. It looks like the tests pass though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants