Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  Arc-style continuations

dmitriid
Posted: Mon Feb 11, 2008 3:07 pm Reply with quote
User Joined: 17 Aug 2006 Posts: 213
I wonder if Arc-style continuations (as in Arc challenge,
http://arclanguage.org/item?id=722) could be implemented in Erlyweb to
enable "magic-style" redirects?

That is, instead of explicitly passing the {ewr, Component, Method,
Params} we could do something like {ewr, Component, Method, {magic,
Params}} and redirect the user to http://site/Component/Method while
preserving all the Params...

At the very least this could be used to implement RoR's flash[:error]...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message
ketralnis
Posted: Mon Feb 11, 2008 5:11 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
> That is, instead of explicitly passing the {ewr, Component, Method,
> Params} we could do something like {ewr, Component, Method, {magic,
> Params}} and redirect the user to http://site/Component/Method while
> preserving all the Params...

You could do this pretty easily with a not-so-fancy fancy session
manager process. Since you're actually specifying the Params that you
want to pass and only preserving those, you don't even need
continuations to do it (unless you're hoping to resume inline, which
it doesn't look like you are).

If you are hoping to resume inline, you could simulate it with
something like:

%% prepare the continuation
session_manager:new(Params,fun(MoreParams) ->
%% additional processing....
{ewc, controller, function2, [results_of(Params,MoreParams)]
end
end),

%% and return the intermediate result
{ewc, controller,function,[foo]}.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message AIM Address
dmitriid
Posted: Mon Feb 11, 2008 5:57 pm Reply with quote
User Joined: 17 Aug 2006 Posts: 213
David King wrote:
Quote:
Quote:
That is, instead of explicitly passing the {ewr, Component, Method, Params} we could do something like {ewr, Component, Method, {magic, Params}} and redirect the user to http://site/Component/Method while preserving all the Params... [/code]
You could do this pretty easily with a not-so-fancy fancy session manager process. Since you're actually specifying the Params that you want to pass and only preserving those, you don't even need continuations to do it (unless you're hoping to resume inline, which it doesn't look like you are). If you are hoping to resume inline, you could simulate it with something like: %% prepare the continuation session_manager:new(Params,fun(MoreParams) -> %% additional processing.... {ewc, controller, function2, [results_of(Params,MoreParams)] end end), %% and return the intermediate result {ewc, controller,function,[foo]}. [/code]
This would still require a fancy session manager that could figure out which request exactly to serve and how to clean up unused requests...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message
ketralnis
Posted: Mon Feb 11, 2008 7:20 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
>> If you are hoping to resume inline, you could simulate it with
>> something like: [...]
> This would still require a fancy session manager that could figure
> out which request exactly to serve and how to clean up unused
> requests...

That's not too hard, though. Just drop a cookie with a session_id (in
unpredictable one, and maybe an IP address/user-agent, to prevent the
most egregious session highjacking), and check the cookie when the
next request comes in. That session presumably now has a function
attached to it to call to get the next result in the chain.

Since a number of nested session-setups could get ugly:

session_manager:new(...
session_manager:new(...

(especially since they'd have to be lexically in reverse-order to the
actual execution order), you might want to set up some simple data-
structure for chaining them:

task:new([fun say_hello/2,
fun ask_how_are_you/2,
fun say_fine_thanks_and_ask_about_weather/2,
| ... ]).

(such that each is defined to, for instance, take the list of
parameters "so far" and return an {{ewc},NewParams})

If you plan to get really busy, you'll need a hash function that takes
some relatively (not necessarily perfectly) unique value (IP/User-
agent?) and maps that to a given session_manager or node, so that you
can have multiple session_managers on several nodes, for ease of load-
balancing.

Cleaning up unused requests without blocking is a little trickier, but
you could just, every N requests or minutes, spawn a process, passing
it a list of
[{session_id,last_used_date} |...], then have it send back to the
session_manager a number of session_manager:delete(Session_id) casts
as appropriate, so that the 'delete's and actual session requests can
be interleaved rather than totally blocking the session_manager.

It's at least conceptually solid, I think Smile


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message AIM Address
Guest
Posted: Tue Feb 12, 2008 1:22 am Reply with quote
Guest
On Feb 11, 2008, at 12:17 PM, Dmitrii 'Mamut' Dimandt wrote:

> David King wrote:
>>
>>> That is, instead of explicitly passing the {ewr, Component, Method,
>>> Params} we could do something like {ewr, Component, Method, {magic,
>>> Params}} and redirect the user to http://site/Component/Method while
>>> preserving all the Params...
>>>
>> You could do this pretty easily with a not-so-fancy fancy session
>> manager process. Since you're actually specifying the Params that you
>> want to pass and only preserving those, you don't even need
>> continuations to do it (unless you're hoping to resume inline, which
>> it doesn't look like you are).
>>
>> If you are hoping to resume inline, you could simulate it with
>> something like:
>>
>> %% prepare the continuation
>> session_manager:new(Params,fun(MoreParams) ->
>> %% additional processing....
>> {ewc, controller, function2, [results_of(Params,MoreParams)]
>> end
>> end),
>>
>> %% and return the intermediate result
>> {ewc, controller,function,[foo]}.
>>
>>
> This would still require a fancy session manager that could figure
> out which request exactly to serve and how to clean up unused
> requests...

I have limited experience with continuation-based web frameworks, but
the one I'm familiar with, SISCweb, has the same issue when it comes
to expiring stale continuations. Having a configurable staleness
interval and a reaper process to kill the stale "continuations" seems
like the easiest way to go.

--Kevin


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum