从
paralleluniverse
以下内容:
fiber、suspendablerunnable和suspendablecallable中的run方法
声明他们可能抛出一个SuspendExecution异常。
@suspendable是我们通过声明throws suspendexecution来指定一个suspendable方法的方法,这很方便,因为suspendexecution是一个选中的异常,所以如果f调用g和g是suspendable的,java编译器会强制我们声明f是suspendable的(而且必须是因为它调用g和g可能是suspended的)。
然而,有时我们不能宣布f来扔吊带。一个例子是f是一个接口方法的实现,我们不能(或者不想)更改接口,使其抛出suspendExecution。
因此,假设方法f在接口i中声明,并且我们希望使其在类c中的实现可挂起。编译器不允许我们声明抛出suspendExecution,因为这将与i中的fs声明冲突。
那么,我们要做的就是用@suspendable注释注释c.f(在co.paralleluniverse.fibers包中)。假设c.f调用park或其他一些声明抛出suspendexecution的可挂起方法g,我们需要用try{}catch(suspendexecution)将fs body包围起来,以便该方法编译。
如果我们想在光纤中运行h,那么它必须是可挂起的,因为它调用可挂起的f。我们可以通过用@suspendable注释h或声明suspendexecution来将h指定为suspendable
如果我们想让任何方法在光纤中运行,那么它必须是可挂起的。
所以基本上,任何调用方法的方法都可以抛出suspendExecution或用
@Suspendable
是的。
在我的情况下,我在打电话时遇到了错误
SubFlow
从函数开始,因为我没有用
@可暂停的
我面对类星体的例外。作为
亚流
用注释
@可暂停的
注释我的函数有助于消除这些错误。
错误:
Uninstrumented whole methods ('**') or single calls ('!!') detected: