Saving state between RPC calls
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Benjamin Polidore <polid... @gmail.com>
Date: Fri, 6 Jul 2012 19:05:00 -0700 (PDT)
Subject: Saving state between RPC calls
hey, this might be a dumb Q, but if you want to save state between RPC method calls, do you have to do anything special? variables i declare outside the return scope are available in the closure, but i can't set them. does socketstream reinstantiate the return object each call to rpc or am i making a silly javascript faux pas?
Here's an example-- this logs Object when it should log Timer:
https://github.com/polidore/ss-angular/blob/rpc/example/server/rpc/ex...
Just to prove I'm not going crazy: this is valid JS.
var a = {} undefined var c = { on: function() { a = 9 }, off: function() {console.log(a); a = 10}} undefined c.on() undefined a 9 c.off() 9 undefined a 10
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Benjamin Polidore <polid... @gmail.com>
Date: Sun, 8 Jul 2012 06:13:27 -0700 (PDT)
Local: Sun, Jul 8 2012 9:13 am
Subject: Re: Saving state between RPC calls
ok, took a look at the source, and it looks like the RPC responders get constructed and discarded each call. I know I could put state in a db, but I'm just trying to write an example app, and if I were to, for example, cache a value in a real application, I can't do it in RPC. Any thoughts?
On Friday, July 6, 2012 10:05:00 PM UTC-4, Benjamin Polidore wrote:
> hey, this might be a dumb Q, but if you want to save state between RPC > method calls, do you have to do anything special? variables i declare > outside the return scope are available in the closure, but i can't set > them. does socketstream reinstantiate the return object each call to rpc or > am i making a silly javascript faux pas?
> Here's an example-- this logs Object when it should log Timer:
> https://github.com/polidore/ss-angular/blob/rpc/example/server/rpc/ex...
> Just to prove I'm not going crazy: this is valid JS.
> var a = {} > undefined > var c = { on: function() { a = 9 }, off: function() {console.log(a); a = > 10}} > undefined > c.on() > undefined > a > 9 > c.off() > 9 > undefined > a > 10
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Owen B <socketstreami... @gmail.com>
Date: Sun, 8 Jul 2012 06:50:07 -0700 (PDT)
Local: Sun, Jul 8 2012 9:50 am
Subject: Re: Saving state between RPC calls
Hey Benjamin
Yes you're right, we need to run the exports.action closure each time to allow the middleware to execute.
Therefore if you really don't want to use a db, just put your variable outside of the closure:
var intervalId = {};
exports.actions = function(req,res,ss) { var crypto = require('crypto');
return { on: function() { etc etc...
Owen
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Benjamin Polidore <polid... @gmail.com>
Date: Sun, 8 Jul 2012 09:59:17 -0400
Local: Sun, Jul 8 2012 9:59 am
Subject: Re: Saving state between RPC calls
Thanks. That makes sense.
On Sun, Jul 8, 2012 at 9:50 AM, Owen B <socketstreami
... @gmail.com> wrote:
> Hey Benjamin
> Yes you're right, we need to run the exports.action closure each time to
> allow the middleware to execute.
> Therefore if you really don't want to use a db, just put your variable
> outside of the closure:
> var intervalId = {};
> exports.actions = function(req,res,ss) {
> var crypto = require('crypto');
> return {
> on: function() {
> etc etc...
> Owen
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Benjamin Polidore <polid... @gmail.com>
Date: Mon, 9 Jul 2012 08:38:48 -0700 (PDT)
Local: Mon, Jul 9 2012 11:38 am
Subject: Re: Saving state between RPC calls
So really anything expensive (such as nodejs require()) should probably be done outside the closure if possible for performance reasons, right?
On Sunday, July 8, 2012 9:59:17 AM UTC-4, Benjamin Polidore wrote:
> Thanks. That makes sense.
> On Sun, Jul 8, 2012 at 9:50 AM, Owen B <socketstreami... @gmail.com> wrote:
>> Hey Benjamin
>> Yes you're right, we need to run the exports.action closure each time to >> allow the middleware to execute.
>> Therefore if you really don't want to use a db, just put your variable >> outside of the closure:
>> var intervalId = {};
>> exports.actions = function(req,res,ss) { >> var crypto = require('crypto');
>> return { >> on: function() { >> etc etc...
>> Owen
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Owen B <socketstreami... @gmail.com>
Date: Mon, 9 Jul 2012 08:49:57 -0700 (PDT)
Local: Mon, Jul 9 2012 11:49 am
Subject: Re: Saving state between RPC calls
In general yes, though require() is a synchronous operation which is cached by Node, so it will only ever load the file once.
The req.use() commands can't live outside the closure as they must be evaluated upon each request.
Owen
On Monday, July 9, 2012 4:38:48 PM UTC+1, Benjamin Polidore wrote:
> So really anything expensive (such as nodejs require()) should probably be > done outside the closure if possible for performance reasons, right?
You must
Sign in before you can post messages.
You do not have the permission required to post.