在单击一个插槽时,我更改了该插槽的内容以提供用户反馈,然后调用一些需要几秒钟才能运行的代码。但是,直到“慢”进程完成后,才会呈现对插槽的更改。有没有办法在“慢”的代码运行之前强制渲染。
在下面的示例中,用户从未看到“正在处理,请稍候...”
class MyTest < Shoes
url '/', :index
url '/result', :result
def index
stack do
my_button=flow do
image './assets/trees.jpg'
para 'Process Image'
end
my_button.click do
my_button.contents[0].hide
my_button.contents[1].text="Processing, please wait ..."
sleep(4) # Simulate slow process
visit '/result'
end
end
end
def result
stack do
para "Finished processing"
end
end
end
Shoes.app查看ruby.c或canvas.c中的Shoes源代码,可以看到对重新绘制或绘制画布的引用。它们可以在鞋内调用吗?
提前感谢
发布于 2009-03-23 14:03:30
这有点老生常谈,但你可以将实际的逻辑转移到一个单独的函数中,如下所示:
def doStuff()
sleep(4) # Simulate slow process
visit '/result'
end并使用timer在单独的线程中运行它:
my_button.click do
my_button.contents[0].hide
my_button.contents[1].text="Processing, please wait ..."
timer(0) { doStuff() }
end发布于 2009-03-24 09:25:22
谢谢。这是一种享受。我还想出了一个使用Thread的解决方案:
def doStuff
sleep(4) # Simulate slow process
visit '/result'
end
.
.
.
my_button=stack do
image "button_image.jpg"
para "Press me"
end
my_button.click do
Thread.new do
doStuff
end
my_button.contents[0].hide
my_button.contents[1].text = "Processing, please wait ..."
end这两种解决方案似乎都像预期的那样有效。
https://stackoverflow.com/questions/672972
复制相似问题