From 6d95c8bb33dad59d793bb94c046b9d1174efdcf0 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 18 Dec 2014 00:15:44 +0200 Subject: [PATCH] Use Future instead of Thread. --- .../com/nutomic/ensichat/bluetooth/ChatService.scala | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala index 6a47a30..7783ef0 100644 --- a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala +++ b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala @@ -17,6 +17,8 @@ import com.nutomic.ensichat.util.Database import scala.collection.SortedSet import scala.collection.immutable.{HashMap, HashSet, TreeSet} +import scala.concurrent.Future +import scala.concurrent.ExecutionContext.Implicits.global import scala.ref.WeakReference object ChatService { @@ -94,13 +96,9 @@ class ChatService extends Service { startBluetoothConnections() } - if (!Crypto.localKeysExist) { - new Thread(new Runnable { - override def run(): Unit = { - Crypto.generateLocalKeys() - } - }).start() - } else + if (!Crypto.localKeysExist) + Future(Crypto.generateLocalKeys()) + else Log.i(Tag, "Service started, address is " + Crypto.getLocalAddress) }