简体   繁体   English

期货的Scala命名约定

[英]Scala naming convention for Futures

What is the naming convention in Scala for function returning result wrapped in Future? Scala中的函数返回结果包含在Future中的命名约定是什么? I have seen code like: 我见过的代码如下:

getResult
getResultF
getResultFtr

Or even 甚至

getResultFuture

If there is no specific convention then I would like to know what is practiced more. 如果没有具体的约定,那么我想知道更多的实践。

I usually don't name methods returning Futures any differently. 我通常不会将返回Futures方法命名为不同的方法。 My reason is that this information is already present in the return type, and will be made clear by any decent IDE upon autocompletion. 我的理由是这些信息已经存在于返回类型中,并且在自动完成时将由任何体面的IDE清楚地表明。

One exception is in the presence of another similar method that doesn't return a Future but does everything synchronously. 一个例外是存在另一个类似的方法,该方法不返回Future但同步执行所有操作。 In that case, I like to clearly differentiate them: 在这种情况下,我想明确区分它们:

def fooSync: A
def fooAsync: Future[A]

That's a pattern I've seen in plenty of libraries. 这是我在很多图书馆看到的模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM