Created
December 27, 2018 07:52
-
-
Save astail/ed21e3027c0e046f917413634fea4030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys.process._ | |
object search { | |
def main: Option[String] = { | |
retry2(iphone) | |
} | |
def iphone: Option[String] = { | |
val ping = try { | |
Process("ping -c 5 192.168.0.20") #&& ("echo okkk") !! | |
} catch { | |
case e: Throwable => "error" | |
} | |
if (ping == "okkk") Some("家にいます") else None | |
} | |
def retry2[R](f: => R, n: Int = 40): R = { | |
if (n > 0) { | |
f match { | |
case Some(s) => f | |
case None => retry2(f, n - 1) | |
} | |
} else f | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment