Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a question about on_start stage #66

Open
linusliu opened this issue Jul 30, 2014 · 3 comments
Open

Have a question about on_start stage #66

linusliu opened this issue Jul 30, 2014 · 3 comments

Comments

@linusliu
Copy link

As mentioned, on_start callbacks provide multiple entry points into the Started Request state. In the example, there are two entries:
on_start :setup_redis_callbacks
on_start :fetch_twitter

I want to know is if both callbacks provides render, what will happen? Will it mess up the output for a client?

@lucasallan
Copy link
Collaborator

This is probably is going to use the first one and ignore the last. However, I'm not completely sure. I'll get back to you soon.

Btw - sorry for the delay to answer you. I have numerous github repos and it's hard to follow all the notifications.

@linusliu
Copy link
Author

I am new to cramp.When I try to modify your first example, I got stucked. What I want to do is hook another two methods on the on_start stage. These two methods are simply reply some message just like the start method, but unfortunately, none of them are working correctly. Maybe you could give me a suggestion why is that.
class HomeAction < Cramp::Action

on_start :start1
on_start :start2

def star1
render "Hello From Start1"
end

def start2
render "Hello From Start2"
end

def start
render "Hello World!"

# Do more stuff

render "Hello World Again!"
finish

end
end

@chall8908
Copy link
Contributor

This is a bit after the fact, but Cramp will render as many times as you like. After the action starts, you can render multiple times to, for example, stream data to a client as you parse it. The only thing you have to be careful of is calling render after finish has been called. I don't know for certain if that will cause any problems, but it can't hurt to be safe.

There's also no order guarantee. There's nothing to say that your on_start callbacks will be gotten to before the start method has finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants