-
-
Save onelson/d1b5a047218496c1ad08 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
def users(): Future[List[User]] = { | |
val pl = Promise[List[User]]() | |
Future { | |
_roster.reloadAndWait() | |
val entries = _roster.getEntries().asScala.toList | |
val futures = entries map { entry => | |
val pu = Promise[User]() | |
Future { // wrap all this stuff in the future just so it doesn't block | |
val target = entry.getUser() | |
connection.sendIqWithResponseCallback(ProfileIQ(target), new StanzaListener() { | |
def processPacket(packet: Stanza) = { | |
if (packet != null && packet.isInstanceOf[ProfileIQ]) { | |
val profile = Profile(packet.asInstanceOf[ProfileIQ]) | |
val user: User = User( | |
name = entry.getName(), | |
jid = entry.getUser(), | |
nick = profile.mention_name, | |
entry = entry | |
) | |
pu.success(user) | |
} else { | |
pu.failure(UserUseless("omg I have no idea")) | |
} | |
} | |
}) | |
} | |
pu.future // our return is a future of whatever results we get from the future above | |
} | |
p1.success(Future.sequence(futures).flatten) | |
} | |
p1.future | |
} |
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
Errors: | |
[error] /Users/vitocutten/playground/v2d2/src/main/scala/v2d2/RoboV2D2.scala:346: type mismatch; | |
[error] found : List[scala.concurrent.Future[Unit]] | |
[error] required: List[v2d2.client.User] | |
[error] pl.success(futures) | |
[error] ^ | |
[error] one error found | |
[error] (compile:compileIncremental) Compilation failed | |
[error] Total time: 1 s, completed Mar 5, 2016 4:59:45 PM | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment