What is the iOS (or RubyMotion) idiom for waiting on a block that executes asynchronously?

后端 未结 4 1176
醉梦人生
醉梦人生 2021-01-03 12:59

I have been pulling my hair out for weeks on this niggling problem, and I just can\'t find any info or tips on how or what to do, so I\'m hoping someone here on the RubyMoti

4条回答
  •  暖寄归人
    2021-01-03 13:13

    as borrrden just said, I'd use a dispatch_semaphore

     def ApiHelper.make_sync(&block)
       @semaphore = Dispatch::Semaphore.new(0)
       BubbleWrap::Reactor.schedule do
         # do your stuff
         @result = block.call()
         @semaphore.signal
       end
       @semaphore.wait
       @result
     end
    

    this is how I'd handle it on Rubymotion

提交回复
热议问题