@@ -95,6 +95,43 @@ export interface KeyValueStore {
95
95
clearAll ( ) : void ;
96
96
}
97
97
98
+ export interface SendOptions {
99
+ /**
100
+ * Makes a type-safe one-way RPC to the specified target service, after a delay specified by the
101
+ * milliseconds' argument.
102
+ * This method is like stetting up a fault-tolerant cron job that enqueues the message in a
103
+ * message queue.
104
+ * The handler calling this function does not have to stay active for the delay time.
105
+ *
106
+ * Both the delay timer and the message are durably stored in Restate and guaranteed to be reliably
107
+ * delivered. The delivery happens no earlier than specified through the delay, but may happen
108
+ * later, if the target service is down, or backpressuring the system.
109
+ *
110
+ * The delay message is journaled for durable execution and will thus not be duplicated when the
111
+ * handler is re-invoked for retries or after suspending.
112
+ *
113
+ * This call will return immediately; the message sending happens asynchronously in the background.
114
+ * Despite that, the message is guaranteed to be sent, because the completion of the invocation that
115
+ * triggers the send (calls this function) happens logically after the sending. That means that any
116
+ * failure where the message does not reach Restate also cannot complete this invocation, and will
117
+ * hence recover this handler and (through the durable execution) recover the message to be sent.
118
+ *
119
+ * @example
120
+ * *Service Side:*
121
+ * ```ts
122
+ * const service = restate.service({
123
+ * ...
124
+ * });
125
+ *
126
+ * ```
127
+ * **Client side:**
128
+ * ```ts
129
+ * ctx.send(service, {delay: 60_000}).anotherAction(1337);
130
+ * ```
131
+ */
132
+ delay ?: number ;
133
+ }
134
+
98
135
export interface ContextDate {
99
136
/** Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
100
137
* This is equivalent to Date.now()
@@ -323,67 +360,14 @@ export interface Context {
323
360
* ```
324
361
*/
325
362
objectSendClient < P extends string , M > (
326
- opts : VirtualObjectDefinition < P , M > ,
327
- key : string
328
- ) : SendClient < M > ;
329
- serviceSendClient < P extends string , M > (
330
- opts : ServiceDefinition < P , M >
363
+ obj : VirtualObjectDefinition < P , M > ,
364
+ key : string ,
365
+ opts ?: SendOptions
331
366
) : SendClient < M > ;
332
367
333
- /**
334
- * Makes a type-safe one-way RPC to the specified target service, after a delay specified by the
335
- * milliseconds' argument.
336
- * This method is like stetting up a fault-tolerant cron job that enqueues the message in a
337
- * message queue.
338
- * The handler calling this function does not have to stay active for the delay time.
339
- *
340
- * Both the delay timer and the message are durably stored in Restate and guaranteed to be reliably
341
- * delivered. The delivery happens no earlier than specified through the delay, but may happen
342
- * later, if the target service is down, or backpressuring the system.
343
- *
344
- * The delay message is journaled for durable execution and will thus not be duplicated when the
345
- * handler is re-invoked for retries or after suspending.
346
- *
347
- * This call will return immediately; the message sending happens asynchronously in the background.
348
- * Despite that, the message is guaranteed to be sent, because the completion of the invocation that
349
- * triggers the send (calls this function) happens logically after the sending. That means that any
350
- * failure where the message does not reach Restate also cannot complete this invocation, and will
351
- * hence recover this handler and (through the durable execution) recover the message to be sent.
352
- *
353
- * @example
354
- * *Service Side:*
355
- * ```ts
356
- * const router = restate.router({
357
- * someAction: async(ctx: restate.RpcContext, req: string) => { ... },
358
- * anotherAction: async(ctx: restate.RpcContext, count: number) => { ... }
359
- * });
360
- *
361
- * // option 1: export only the type signature of the router
362
- * export type myApiType = typeof router;
363
- *
364
- * // option 2: export the API definition with type and name (name)
365
- * export const myApi: restate.ServiceApi<typeof router> = { name : "myservice" };
366
- *
367
- * restate.createServer().bindRouter("myservice", router).listen(9080);
368
- * ```
369
- * **Client side:**
370
- * ```ts
371
- * // option 1: use only types and supply service name separately
372
- * ctx.sendDelayed<myApiType>({name: "myservice"}, 60_000).someAction("hello!");
373
- *
374
- * // option 2: use full API spec
375
- * ctx.sendDelayed(myApi, 60_000).anotherAction(1337);
376
- * ```
377
- */
378
- objectSendDelayedClient < P extends string , M > (
379
- opts : VirtualObjectDefinition < P , M > ,
380
- delay : number ,
381
- key : string
382
- ) : SendClient < M > ;
383
-
384
- serviceSendDelayedClient < P extends string , M > (
385
- opts : ServiceDefinition < P , M > ,
386
- delay : number
368
+ serviceSendClient < P extends string , M > (
369
+ service : ServiceDefinition < P , M > ,
370
+ opts ?: SendOptions
387
371
) : SendClient < M > ;
388
372
389
373
/**
0 commit comments