88// the Business Source License, use of this software will be governed
99// by the Apache License, Version 2.0.
1010
11- use std:: collections:: HashSet ;
1211use std:: num:: NonZeroUsize ;
1312use std:: ops:: Deref ;
1413use std:: pin:: Pin ;
@@ -38,7 +37,7 @@ use restate_service_protocol_v4::entry_codec::ServiceProtocolV4Codec;
3837use restate_service_protocol_v4:: message_codec:: {
3938 Decoder , Encoder , Message , MessageHeader , MessageType , StateEntry , proto,
4039} ;
41- use restate_types:: errors:: InvocationError ;
40+ use restate_types:: errors:: { GenericError , InvocationError } ;
4241use restate_types:: identifiers:: InvocationId ;
4342use restate_types:: identifiers:: ServiceId ;
4443use restate_types:: invocation:: {
@@ -51,7 +50,7 @@ use restate_types::journal_v2::command::{
5150} ;
5251use restate_types:: journal_v2:: raw:: { RawCommand , RawEntry , RawNotification } ;
5352use restate_types:: journal_v2:: {
54- CommandIndex , CommandType , Entry , EntryType , NotificationId , RunCompletion , RunResult , SignalId ,
53+ CommandIndex , CommandType , Entry , EntryType , RunCompletion , RunResult , UnresolvedFuture ,
5554} ;
5655use restate_types:: schema:: deployment:: { Deployment , DeploymentType , ProtocolType } ;
5756use restate_types:: schema:: invocation_target:: { DeploymentStatus , InvocationTargetResolver } ;
@@ -849,6 +848,7 @@ where
849848 MessageType :: CommandAck ,
850849 ) ) ,
851850 Message :: Suspension ( suspension) => self . handle_suspension_message ( suspension) ,
851+ Message :: AwaitingOn ( awaiting_on) => self . handle_awaiting_on_message ( awaiting_on) ,
852852 Message :: Error ( e) => self . handle_error_message ( e) ,
853853 Message :: End ( _) => TerminalLoopState :: Closed ,
854854
@@ -1171,34 +1171,35 @@ where
11711171 }
11721172 }
11731173
1174+ fn handle_awaiting_on_message (
1175+ & mut self ,
1176+ _awaiting_on : proto:: AwaitingOnMessage ,
1177+ ) -> TerminalLoopState < ( ) > {
1178+ // this message should mark this invocation as suspendable.
1179+ // if it's not running any side effects.
1180+ todo ! ( "Handle awaiting on message" ) ;
1181+ }
1182+
11741183 fn handle_suspension_message (
11751184 & mut self ,
11761185 suspension : proto:: SuspensionMessage ,
11771186 ) -> TerminalLoopState < ( ) > {
1178- let suspension_indexes: HashSet < _ > = suspension
1179- . waiting_completions
1180- . into_iter ( )
1181- . map ( NotificationId :: for_completion)
1182- . chain (
1183- suspension
1184- . waiting_signals
1185- . into_iter ( )
1186- . map ( SignalId :: for_index)
1187- . map ( NotificationId :: for_signal) ,
1188- )
1189- . chain (
1190- suspension
1191- . waiting_named_signals
1192- . into_iter ( )
1193- . map ( |s| SignalId :: for_name ( s. into ( ) ) )
1194- . map ( NotificationId :: for_signal) ,
1195- )
1196- . collect ( ) ;
1197- // We currently don't support empty suspension_indexes set
1198- if suspension_indexes. is_empty ( ) {
1187+ let Some ( awaiting_on) = suspension. awaiting_on else {
1188+ return TerminalLoopState :: Failed ( InvokerError :: EmptySuspensionMessage ) ;
1189+ } ;
1190+
1191+ let combinator: UnresolvedFuture = match awaiting_on. try_into ( ) . map_err ( GenericError :: from)
1192+ {
1193+ Ok ( combinator) => combinator,
1194+ Err ( err) => return TerminalLoopState :: Failed ( InvokerError :: EncodingV2 ( err. into ( ) ) ) ,
1195+ } ;
1196+
1197+ // We currently don't support empty combinator set
1198+ if combinator. is_empty ( ) {
11991199 return TerminalLoopState :: Failed ( InvokerError :: EmptySuspensionMessage ) ;
12001200 }
1201- TerminalLoopState :: SuspendedV2 ( suspension_indexes)
1201+
1202+ TerminalLoopState :: SuspendedV2 ( combinator)
12021203 }
12031204
12041205 fn handle_error_message ( & mut self , error : proto:: ErrorMessage ) -> TerminalLoopState < ( ) > {
0 commit comments