cramp icon indicating copy to clipboard operation
cramp copied to clipboard

Have a question about on_start stage

Open linusliu opened this issue 10 years ago • 3 comments

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?

linusliu avatar Jul 30 '14 22:07 linusliu

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.

lucasallan avatar Aug 10 '14 16:08 lucasallan

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

linusliu avatar Aug 11 '14 01:08 linusliu

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.

chall8908 avatar Oct 20 '14 18:10 chall8908