2012-04-26 1 views
0

現時点でかなり不満な問題を抱えています。Meteor HTTP GETがMongoループ内でクラッシュする

私はMeteor.http.get呼び出しを行うことができますが、ループに入れると悪いことが起こります。

私は何をやっているのかと100%確信しているわけではないので、どのポインタも素晴らしいでしょう!

このコードは動作します - それは、このコードがクラッシュ

のCoffeeScriptです:このエラーで

things.forEach((thing) -> 
    console.log thing.url # it logs http://some_site.com/feed.rss 
    Meteor.http.get(thing.url, (error, results) -> 
    if results.statusCode is 200 
     console.log results.content 
) 
)) 

:1 あなたのアプリケーションがクラッシュしている:

node.js:201 
    throw e; // process.nextTick error, or 'error' event on first tick 
     ^
TypeError: Cannot read property '_meteor_dynamics' of undefined 
at Object.bindEnvironment (app/packages/meteor/dynamics_nodejs.js:48:44) 
at Object.call (app/packages/http/httpcall_server.js:72:25) 
at Object.get (app/packages/http/httpcall_common.js:40:29) 
at app/craftcandy.coffee.js:112:28 
at app/packages/mongo-livedata/mongo_driver.js:307:7 
at /usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/cursor.js:173:11 
at [object Object].nextObject (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/cursor.js:485:5) 
at Object.callback (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/cursor.js:478:12) 
at Array.0 (/usr/local/meteor/lib/node_modules/mongodb/lib/mongodb/connection/server.js:197:36) 
at EventEmitter._tickCallback (node.js:192:41) 

はコードで終了しました。ファイルの変更を待っています。

+0

Things.find().forEach(function(thing){ var url = thing.url; console.log("geting " + url); (function (_url){ try{ Meteor.http.get(_url, function(error, results){ if(results.statusCode === 200){ console.log("request success: " + _url); } else { console.log("request error: " + _url); } }); } catch (e) { // if it gets here you probly have a malformed url console.log("meteor error!: "+_url); } })(url); }); 

はここcoffeestriptにそれを翻訳する時、私のテストされていない試みです0.3.4。あなたのポストはそれを捕まえました、ありがとう。 – debergalis

答えて

0

流星がフードの下でnode.jsを使用していて、node.jsが非同期で非ブロックであることが原因と考えられます。

ので、代わりにresults.statusCodeをチェックする、多分コールバック(私のCoffeeScriptはご容赦)内に置く:申し訳ありませんが、事前にスクリプトの構文が間違っている場合

things.forEach((thing) -> 
    console.log thing.url # it logs http://some_site.com/feed.rss 
    Meteor.http.get(thing.url, (error, results) -> 
     results.on('data', (d) -> 
     //Do something here with the data stream 
    ) 

     results.on('end', (rslts) -> 
     //Do something here with the results stream, like log to console: 
     console.log rslts.content 
    ) 
    ) 
) 

を。私が言ったように、私はcoffeescript(まだ)を話しません。

しかし、あなたは要点を得る。私はこれをnode.js questionから食い止めました。それが動作するかどうか私に教えてください。

0

あなたのコードに何か間違っているか、あなたのURLの1つがフォーマットされていないと思われます。あなたはこのようにそれをテストしてみることができます。これは、今では固定流星の `Cursor.prototype.forEach`、バグだった

Things.find().forEach (thing) -> 
    url = thing.url 
    console.log "geting: " + url 
    go = (_url) -> 
    try 
     Meteor.http.get _url, (error, results) -> 
     if results.statusCode is 200 
      console.log "request success: " + _url 
     else 
      console.log "request error: " + _url 

    catch e 
     # if it gets here you probly have a malformed url 
     console.log "meteor error!: "+ _url 

    go url 
関連する問題