Skip to content

Commit fa09a30

Browse files
committed
Add non-botbase run_until().
1 parent 3a27067 commit fa09a30

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

SerialPrograms/Source/CommonFramework/InferenceInfra/InferenceRoutines.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66

77
#include "Common/Cpp/Exceptions.h"
8-
//#include "Common/Cpp/Concurrency/AsyncDispatcher.h"
98
#include "ClientSource/Connection/BotBase.h"
10-
//#include "CommonFramework/Tools/ProgramEnvironment.h"
119
#include "InferenceSession.h"
1210
#include "InferenceRoutines.h"
1311

@@ -46,6 +44,31 @@ int wait_until(
4644

4745

4846

47+
int run_until(
48+
VideoStream& stream, CancellableScope& scope,
49+
std::function<void(CancellableScope& scope)>&& command,
50+
const std::vector<PeriodicInferenceCallback>& callbacks,
51+
std::chrono::milliseconds default_video_period,
52+
std::chrono::milliseconds default_audio_period
53+
){
54+
CancellableHolder<CancellableScope> subscope(scope);
55+
InferenceSession session(
56+
subscope, stream,
57+
callbacks,
58+
default_video_period, default_audio_period
59+
);
60+
61+
try{
62+
if (command){
63+
command(subscope);
64+
}
65+
}catch (OperationCancelledException&){}
66+
67+
subscope.throw_if_cancelled_with_exception();
68+
scope.throw_if_cancelled();
69+
70+
return session.triggered_index();
71+
}
4972
int run_until(
5073
VideoStream& stream, BotBaseContext& context,
5174
std::function<void(BotBaseContext& context)>&& command,

SerialPrograms/Source/CommonFramework/InferenceInfra/InferenceRoutines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ inline int wait_until(
6060
//
6161
// Exceptions thrown in either the commands or the callbacks will stop
6262
// everything and will be propagated out of this function.
63+
int run_until(
64+
VideoStream& stream, CancellableScope& scope,
65+
std::function<void(CancellableScope& scope)>&& command,
66+
const std::vector<PeriodicInferenceCallback>& callbacks,
67+
std::chrono::milliseconds default_video_period = std::chrono::milliseconds(50),
68+
std::chrono::milliseconds default_audio_period = std::chrono::milliseconds(20)
69+
);
6370
int run_until(
6471
VideoStream& stream, BotBaseContext& context,
6572
std::function<void(BotBaseContext& context)>&& command,

0 commit comments

Comments
 (0)