Problems with nodejs co library

  node.js, question

The program code is as follows:

var arp = require('node-arp');
 var co = require('co');
 
 
 function getMAC(ipAddress) {
 return function (callback) {
 arp.getMAC(ipAddress, callback);
 bracket
 bracket
 
 
 co(function*(){
 var address=[
 '192.168.1.100',
 '192.168.1.101'
 ];
 var p1=yield getMAC(address[0]);
 var p2=yield getMAC(address[1]);
 
 Log (address [0] plus'->' plus p1);
 Log (address [1] plus'->' plus p2);
 return 'done';
 })(function(err,result){
 Log ('err:' plus err plus', result:' plus result');
 });

I wrote with reference to other people’s blogs: I don’t know much about co and yield why.

Debugger listening on port 18507
 f:\nodejs\node-study\generator\Test4.js:27
 })(function(err,result){
 ^
 TypeError: object is not a function

Ask for an answer. . .

Two questions:

  1. What version of node do you use? Suggested usenode5.1.0-stableBecause it is supported by defaultgenerator

  2. What’s your problem, did you get it? Or what else

Look at the mistake should becoThe version of the problem, see the following document description:

co@4.0.0 has been released, which now relies on promises. It is a stepping stone towards ES7 async/await. The primary API change is how co() is invoked. Before, co returned a “thunk”, which you then called with a callback and optional arguments. Now, co() returns a promise.

Because of this new editioncoChange the main API and do not return any more.thunkFunction, but returns apromise, so your code can be changed to the following way:

co(function*(){
 var address=[
 '192.168.1.100',
 '192.168.1.101'
 ];
 var p1=yield getMAC(address[0]);
 var p2=yield getMAC(address[1]);
 
 Log (address [0] plus'->' plus p1);
 Log (address [1] plus'->' plus p2);
 return 'done';
 })
 .then(function(err, result){
 Log ('err:' plus err plus', result:' plus result');
 });