Scala,unsafeRunSync-为什么每次都需要调用它?

我有一个奇怪的问题。我创建了两个方法,它们返回Lists

override def createContributorsList(url: String,params: String): F[List[Contributor]] = getcontributorsFromClient(url,params).fold[List[Contributor]](_ => List(),res => res)

override def createReposList(organization: String,params: String): F[List[GitRepository]] = getReposFromClient(organization,params).fold[List[GitRepository]](_ => List(),res => res)

现在我想调用这些方法(它们连接到Git存储库并获取给定组织的贡献者):

val res = for {
    repos <- stats.createReposList("github","")
    contr = repos.foreach(r => println(stats.createContributorsList(r.contributors_url,"").unsafeRunSync()))
  } yield (repos,contr)
 res.unsafeRunSync

如您所见,我需要调用unsafeRunSync方法两次以检索所有数据。为什么我需要这样做?可以用其他方式完成吗?我想我应该只运行一次unsafeRunSync-当我需要运行程序时,而不是一直运行。

fei2008e 回答:Scala,unsafeRunSync-为什么每次都需要调用它?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3127662.html

大家都在问