Still talking meteor 0.6.4 here, changeset here
Reviewing the docs I noted that during deployment you need to deal sometimes with fibers which I have seen referenced to futures. So I decided to see what I could glean from finding it.
ls .meteor/local/build/server/node_modules/fibers/
Then not having noticed anything jump out at me immedeately, searched and found some references
Sources
- http://stackoverflow.com/questions/12569712/meteor-calling-an-asynchronous-function-inside-a-meteor-method-and-returning-th
- https://github.com/semateos/meteor-async-test
Added this, which fails
Meteor.startup -> require = __meteor_bootstrap__.require Future = require('future'); return
As you can see
[26/5/2013][13:49:1.805][SERVER][Observatory][VERBOSE][] Creating logger with level DEBUG, print to console: true, log user: true TypeError: undefined is not a function at app/server/Server.coffee.js:7:19 at run (/revoltdc_hackathon_20130622_continued/.meteor/local/build/server/server.js:329:63) at Array.forEach (native) at Function._.each._.forEach (/.meteorite/meteors/meteor/meteor/9bb2b5447e845c4f483df5e9b42a2c1de5ab909b/dev_bundle/lib/node_modules/underscore/underscore.js:78:11) at run (/revoltdc_hackathon_20130622_continued/.meteor/local/build/server/server.js:329:7)
Removed
Meteor.startup -> require = __meteor_bootstrap__.require Future = require('future'); return
Result:
Server doesn’t crash
Searched more: meteor futures fiber
Source
In the code below, I attempt at first to use just a single future object, but the server complained. I believe there is a way to do this, but this isn’t it. Anyhow, I added two futures. The result is the same; perhaps setting the session in the router is the real issue.
checkCapitolWords: (query) -> Future = Npm.require("fibers/future"); fut = new Future() fut2 = new Future() result = Meteor.http.call('GET',"http://congress.api.sunlightfoundation.com/legislators", params: "apikey": sunlight_api_key, "last_name": query, ,(err,res)-> return fut.ret(res) ) result = fut.wait() console.log( query + " is query") if result.statusCode is 200 resulting = JSON.parse(result.content); console.log( resulting.results[0].bioguide_id ) bioguide_id = resulting.results[0].bioguide_id capitol_by_leg = Meteor.http.call('GET',"http://capitolwords.org/api/1/phrases.json" params: "apikey": sunlight_api_key, "entity_type": "legislator", "entity_value": bioguide_id (err,res)-> return fut2.ret(res) ) capitol_by_leg = fut2.wait() if capitol_by_leg.statusCode is 200 resulting = JSON.parse(capitol_by_leg.content); resulting.sort (a, b)-> return b.count - a.count console.log(resulting) return resulting else return resulting false
So let’s review what I learned from failure.
- There exists a meteor bootstrap function I can use to require stuff
- I can use a future to guarantee waiting on a callback
- Most people suggest using a collection to update, which in turn will behave reactively, the session may be a poor choice here
- The regular future object can’t be reused
- The location of fibers in the local hidden directory
- Is there a way to use one meteor method to call another?
- If so, will my this work differently?
- We should verify using a collection to update will in turn will behave reactively
No comments:
Post a Comment