Async call generates “ Error: Can't wait without a ”fiber\", even with _wrapAsync

我的未来我决定 提交于 2019-12-01 14:40:28

Meteor._wrapAsync() expects the wrapped function to return error and result to a callback. Your function, getBlog(), does not do that so _wrapAsync is not the right approach.

I have wrapped that function before but used a Future.

That approach allowed me to call feedparser from a Meteor.method(), which doesn't allow async functions, but you are also trying to do an insert inside the readable event. I think that insert will complain if it is not in a fiber. Maybe like this would also be necessary:

var r = request( parameter );
r.on( 'response' , function(){

  var fp = r.pipe( new FeedParser() );  //need feedparser object as variable to pass to bindEnvironment 

  fp.on('readable', Meteor.bindEnvironment( 
    function () {
      var stream = this,
        item;
      while (item = stream.read()) {         
        Items.insert(new_item);                
      }
    }
    , function( error ){ console.log( error );}
    , fp // variable applied as `this` inside call of first function 
  ));
});

Fibers is another option...

var Fiber = Npm.require( "fibers" );

 .on('readable', function () {
    var stream = this,
        item;
    while (item = stream.read()) {         
        Fiber( function(){
          Items.insert(new_item);
          Fiber.yield();
        }).run();                
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!