title: Clean up SimplePing code with RunLoop.current.run
body: <p>I found the <a href="https://developer.apple.com/library/archive/samplecode/SimplePing/Introduction/Intro.html" rel="nofollow noreferrer">SimplePing</a> library from Apple and want to use it in a SwiftUI Project.</p>
  <p>To use the library I code online which works fine. The <code>start</code> function is as follows:</p>
  <pre><code>public func start(hostName: String) {
      
      let pinger = SimplePing(hostName: &quot;192.168.178.20&quot;)
      pinger.delegate = self
      pinger.start()
      
      var count = 5
      repeat {
          if (self.canStartPinging) {
              pinger.send(with: nil)
              count-=1                
              if count == 0{
                  self.canStartPinging = false
                  break
              }
          }
          RunLoop.current.run(mode: RunLoop.Mode.default, before: NSDate.distantFuture)
      } while(true)
  </code></pre>
  <p>I don't really understand why I need the <code>RunLoop.current.run(mode: RunLoop.Mode.default, before: NSDate.distantFuture)</code> line. When I remove it the delegates of SimplePing doesn't get called.</p>
  <p>How can I simplify this code and use it without blocking the Main thread?</p>