src/runtime/party/party.c
static inline par_t* party_promise_await_on_futures(pony_ctx_t **ctx,
                                                    par_t *par,
                                                    closure_t *call,
                                                    closure_t *cmp){
  array_t *fut_list = collect_future_from_party(ctx, par);
  size_t size = array_size(fut_list);

  if (!size) {
    // runs synchronously. it is up to the call closure to divide and conquer
    // TODO: if there are tasks spawned within the closure, the args array
    //       is allocated on the stack and the arguments may be gone by the time
    //       the tasks start doing any work (no use of task, at the moment)
    value_t args[] = { [0] = { .p = par }, [1] = { .p = cmp }};
    return (par_t *) closure_call(ctx, call, args).p;
  }

  // INFO: make sure the promise is fulfilled with a ParT type.
  future_t *promise = future_mk(ctx, &party_type);

  struct env_collect_from_party *env = encore_alloc(*ctx, sizeof(struct env_collect_from_party));
  env->counter = size;
  env->par = par;
  env->promise = promise;
  env->call = call;
  env->cmp = cmp;

  closure_t *c = closure_mk(ctx, grouping_futures_async,
                            env, trace_collect_from_party, NULL);

  for(size_t i=0; i < size; ++i){
    future_t *future = array_get(fut_list, i).p;
    future_register_callback(ctx, future, c);
  }
  future_await(ctx, promise);
  return (par_t *) future_get_actor(ctx, promise).p;
}
// This is a helper function for the common pattern of awaiting until all
// futures have been fulfilled and fulfilling a promise to continue.
// INFO: the promise needs to be fulfilled with a ParT. if this is not the
//       case, the tracing of the promise will fail.
This is a helper function for the common pattern of awaiting until all
futures have been fulfilled and fulfilling a promise to continue.
INFO: the promise needs to be fulfilled with a ParT. if this is not the
case, the tracing of the promise will fail.
This is a helper function for the common pattern of awaiting until all futures have been fulfilled and fulfilling a promise to continue . INFO : the promise needs to be fulfilled with a ParT . if this is not the case the tracing of the promise will fail .
static inline par_t* party_promise_await_on_futures(pony_ctx_t **ctx,
                                                    par_t *par,
                                                    closure_t *call,
                                                    closure_t *cmp){
  array_t *fut_list = collect_future_from_party(ctx, par);
  size_t size = array_size(fut_list);
  if (!size) {
    value_t args[] = { [0] = { .p = par }, [1] = { .p = cmp }};
    return (par_t *) closure_call(ctx, call, args).p;
  }
  future_t *promise = future_mk(ctx, &party_type);
  struct env_collect_from_party *env = encore_alloc(*ctx, sizeof(struct env_collect_from_party));
  env->counter = size;
  env->par = par;
  env->promise = promise;
  env->call = call;
  env->cmp = cmp;
  closure_t *c = closure_mk(ctx, grouping_futures_async,
                            env, trace_collect_from_party, NULL);
  for(size_t i=0; i < size; ++i){
    future_t *future = array_get(fut_list, i).p;
    future_register_callback(ctx, future, c);
  }
  future_await(ctx, promise);
  return (par_t *) future_get_actor(ctx, promise).p;
}
static inline par_t * party_promise_await_on_futures ( pony_ctx_t * * ctx , par_t * par , closure_t * call , closure_t * cmp ) { array_t * fut_list = collect_future_from_party ( ctx , par ) ; size_t size = array_size ( fut_list ) ; if ( ! size ) { value_t args [ ] = { [ 0 ] = { . p = par } , [ 1 ] = { . p = cmp } } ; return ( par_t * ) closure_call ( ctx , call , args ) . p ; } future_t * promise = future_mk ( ctx , & party_type ) ; struct env_collect_from_party * env = encore_alloc ( * ctx , sizeof ( struct env_collect_from_party ) ) ; env -> counter = size ; env -> par = par ; env -> promise = promise ; env -> call = call ; env -> cmp = cmp ; closure_t * c = closure_mk ( ctx , grouping_futures_async , env , trace_collect_from_party , NULL ) ; for ( size_t i = 0 ; i < size ; ++ i ) { future_t * future = array_get ( fut_list , i ) . p ; future_register_callback ( ctx , future , c ) ; } future_await ( ctx , promise ) ; return ( par_t * ) future_get_actor ( ctx , promise ) . p ; }
This is a helper function for the common pattern of awaiting until all
futures have been fulfilled and fulfilling a promise to continue.
This is a helper function for the common pattern of awaiting until all futures have been fulfilled and fulfilling a promise to continue .
// runs synchronously. it is up to the call closure to divide and conquer // TODO: if there are tasks spawned within the closure, the args array //       is allocated on the stack and the arguments may be gone by the time //       the tasks start doing any work (no use of task, at the moment) // INFO: make sure the promise is fulfilled with a ParT type.