我在RubyMotion应用程序中执行此操作:
Dispatch::Queue.concurrent('google').async {
BubbleWrap::HTTP.get("http://google.com") do |response|
p response.body.to_str
end
}
此通话未完成。
但是,如果我在Dispatch队列之外使用BubbleWrap代码,它就可以了。
答案 0 :(得分:4)
BubbleWrap::HTTP
是对NSURLConnection
的抽象,它依赖于RunLoop进行异步处理。不幸的是,RunLoops没有设置在GCD队列上,我还没想出如何在GCD队列上启动runloop。当我需要上述内容时,我使用了实例化新的NSThread
,并手动启动了运行循环:
action = lambda do
runLoop = NSRunLoop.currentRunLoop
BW::HTTP.get("http://www.google.com") do |response|
NSLog("Fetched Google!")
end
runLoop.run
end
thread = NSThread.alloc.initWithTarget action, selector:"call", object:nil
thread.start
的重复