Does function that calls a non-async function become non-async?


#1

I have a C3 function functionA which invokes another function functionB, and functionB is a non-async function because it call refreshCalcFields with async to be false, like following,

function functionB(email) {
  // do something

  Type.refreshCalcFields({
    ids: [ids],
    calcFieldsToRefresh: ['field'],
    async: false
  });

  return true;
}

function functionA(name, email) {
  // do something
  this.functionB(email);
  return true;
}

In this case, is functionA an async function or a non-async function? i.e., does functionA return true after refreshCalcFields completes and functionB return true?

Note: we don’t assign this.functionB(email) to any variable inside functionA.


#2

Functions are just code that can be executed (you also get some context, like the language, the runtime, etc.). Functions are not intrinsically sync or async, their execution is.
Currently, in C3 apps code the “asynchronous” mechanism is done via queues: you put your action in a queue and a worker will pick up the task, do the work and store a result somewhere.

The emphasis on code vs. execution can be seen in the difference between:

  1. executing a method on a type: MyType.functionA() (synchronous)
  2. delegating the execution to the Action Queue: ActionQueue.submitAction(MyType, 'functionA') (where functionA will be called “asynchronously”)

In your example Type.refreshCalcFields is actually called synchronously (it has to). Internally it looks at the value of async field on the spec and decides whether to execute the function right now, or to delegate its execution to a Queue, in which case it upserts the task into the Queue and returns immediately with a handle to the queue entry (aka a “job” with an id so you can retrieve it later).


#3

Is there something specified that is related to scheduling? For example, if I call submitAction, can I prevent the caller from being paused at the benefit of the callee (which is started from the queue)?


#4

@AlexBakic Putting the entry in the queue doesn’t wait for it to be executed. It will be executed when scheduled via the invalidation queue mechanism.


#5

How does the invalidation queue mechanism interact with the other (scheduling) mechanisms? In particular, can the caller be preempted when enqueueing an action entry?
Thanks


#6

It is just a set and forget thing. Meaning, the caller has no interaction with the action at all, either before, during, or after its execution.