eventual icon indicating copy to clipboard operation
eventual copied to clipboard

Event with ActivityToken and Signal with ActivityToken

Open thantos opened this issue 3 years ago • 0 comments

Support sending an event or a signal from the workflow with an activity token without starting a workflow.

note: not sure how to make this ergonomic

In an example I have...

const RequestApprovalEvent =
  event<RequestApprovalEventPayload>("RequestApproval");

// auto approval for the human request approval event.
RequestApprovalEvent.on(async (event) => {
  await requestApproval.complete({
    activityToken: event.token,
    result: { approve: true },
  });
});

workflow(async () => {
  await requestApproval({
    price,
    recommendation: decision,
    symbol,
  });
});

const requestApproval = activity(
  "requestApproval",
  async (event: Omit<RequestApprovalEventPayload, "token">) => {
    return asyncResult<{ approve: boolean }>(async (token) => {
      await RequestApprovalEvent.publish({ ...event, token });
    });
  }
);

Should be able to do this like...

const requestApprovalEventActivity = asyncEventActivity((token, data: Omit<RequestApprovalEventPayload, "token">) => ({ 
   ...data, 
   token
}));

workflow(async () => {
  await requestApprovalEventActivity({
    price,
    recommendation: decision,
    symbol,
  });
});

thantos avatar Dec 14 '22 02:12 thantos