Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Saving state between RPC calls
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
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:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Benjamin Polidore  
View profile  
 More options Jul 6 2012, 10:05 pm
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Polidore  
View profile  
 More options Jul 8 2012, 9:13 am
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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Owen B  
View profile   Translate to Translated (View Original)
 More options Jul 8 2012, 9:50 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Polidore  
View profile   Translate to Translated (View Original)
 More options Jul 8 2012, 9:59 am
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Polidore  
View profile  
 More options Jul 9 2012, 11:38 am
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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Owen B  
View profile   Translate to Translated (View Original)
 More options Jul 9 2012, 11:49 am
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »