添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Whats the best practice here to annotate a method as @Suspendable ? In a Flow, there may be multiple private methods that query the vault/ compute business logic. Should these be annotated with @Suspendable so it can recover if a node crashes midway?

Or is @Suspendable only for methods where send / sendAndReceived are involved where its waiting for responses from counterparties?

Anything that initiates flow with other nodes or notary. Eg: A function that calls SubFlow(This flow initiates sessions with other nodes.) The function should be annotated with @Suspendable else I see quasar errors all over. Kid101 Jun 30, 2018 at 7:49 What about just normal methods that just do query/computation? Any benefits from adding @Suspendable? Adrian Jun 30, 2018 at 9:29 I don't think so. I couldn't find any functions in CordaRPCOps.kt annotated with @Suspendable. so basically functions like sub-flow, sendReceive etc that are marked with suspendable should be called from functions that are itself marked suspendable. Kid101 Jun 30, 2018 at 10:08

From paralleluniverse :

The run methods in Fiber, SuspendableRunnable, and SuspendableCallable declare that they may throw a SuspendExecution exception.

@Suspendable is our way to specify a suspendable method is by declaring throws SuspendExecution.This is convenient because SuspendExecution is a checked exception, so if f calls g and g is suspendable, the Java compiler will force us to declare that f is suspendable (and it must be because it calls g and g might be suspended).

Sometimes, however, we cannot declare f to throw SuspendExecution. One example is that f is an implementation of an interface method, and we cannot (or don’t want to) change the interface so that it throws SuspendExecution.

So, suppose method f is declared in interface I, and we’d like to make its implementation in class C suspendable. The compiler will not let us declare that we throw SuspendExecution because that will conflict with f’s declaration in I.

What we do, then, is annotate C.f with the @Suspendable annotation (in the co.paralleluniverse.fibers package). Assuming C.f calls park or some other suspendable method g – which does declare throws SuspendExecution, we need to surround f’s body with try {} catch(SuspendExecution) just so the method will compile.

if we want to run h in a fiber, then it must be suspendable because it calls f which is suspendable. We could designate h as suspendable either by annotating it with @Suspendable or by declaring SuspendExecution

If we want any method to run in a fiber, then it must be suspendable. so basically, any method that calls a method which can throw SuspendExecution or is annotated with @Suspendable .

In my case I faced error calling SubFlow from a function, since I didn't annotate it with @Suspendable I faced Quasar Exceptions. As SubFlow is annotated with @Suspendable annotating my function helped get rid of those errors. Error: Uninstrumented whole methods ('**') or single calls ('!!') detected:

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .