Skip to content

Commit 5a2870d

Browse files
committed
Added more paramless overloads to FunctionsRegistry
1 parent 784d777 commit 5a2870d

File tree

2 files changed

+73
-38
lines changed

2 files changed

+73
-38
lines changed

Core/Cleipnir.ResilientFunctions/FunctionsRegistry.cs

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -210,46 +210,66 @@ public ActionRegistration<TParam> RegisterAction<TParam>(
210210
settings
211211
);
212212

213-
// ** PARAMLESS ** //
214-
public ParamlessRegistration RegisterParamless(
215-
FunctionTypeId functionTypeId,
216-
Func<Workflow, Task<Result>> inner,
217-
Settings? settings = null
218-
) => RegisterParamless(
219-
functionTypeId,
220-
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
221-
settings
222-
);
223-
224-
public ParamlessRegistration RegisterParamless(
225-
FunctionTypeId functionTypeId,
226-
Func<Task<Result>> inner,
227-
Settings? settings = null
228-
) => RegisterParamless(
229-
functionTypeId,
230-
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
231-
settings
232-
);
213+
// ** PARAMLESS ** //
214+
public ParamlessRegistration RegisterParamless(
215+
FunctionTypeId functionTypeId,
216+
Func<Task<Result>> inner,
217+
Settings? settings = null
218+
) => RegisterParamless(
219+
functionTypeId,
220+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
221+
settings
222+
);
233223

234-
public ParamlessRegistration RegisterParamless(
235-
FunctionTypeId functionTypeId,
236-
Func<Workflow, Task> inner,
237-
Settings? settings = null
238-
) => RegisterParamless(
239-
functionTypeId,
240-
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
241-
settings
242-
);
224+
public ParamlessRegistration RegisterParamless(
225+
FunctionTypeId functionTypeId,
226+
Func<Workflow, Task<Result>> inner,
227+
Settings? settings = null
228+
) => RegisterParamless(
229+
functionTypeId,
230+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
231+
settings
232+
);
233+
234+
public ParamlessRegistration RegisterParamless(
235+
FunctionTypeId functionTypeId,
236+
Func<Task<Result<Unit>>> inner,
237+
Settings? settings = null
238+
) => RegisterParamless(
239+
functionTypeId,
240+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
241+
settings
242+
);
243+
244+
public ParamlessRegistration RegisterParamless(
245+
FunctionTypeId functionTypeId,
246+
Func<Workflow, Task<Result<Unit>>> inner,
247+
Settings? settings = null
248+
) => RegisterParamless(
249+
functionTypeId,
250+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
251+
settings
252+
);
243253

244-
public ParamlessRegistration RegisterParamless(
245-
FunctionTypeId functionTypeId,
246-
Func<Task> inner,
247-
Settings? settings = null
248-
) => RegisterParamless(
249-
functionTypeId,
250-
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
251-
settings
252-
);
254+
public ParamlessRegistration RegisterParamless(
255+
FunctionTypeId functionTypeId,
256+
Func<Task> inner,
257+
Settings? settings = null
258+
) => RegisterParamless(
259+
functionTypeId,
260+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
261+
settings
262+
);
263+
264+
public ParamlessRegistration RegisterParamless(
265+
FunctionTypeId functionTypeId,
266+
Func<Workflow, Task> inner,
267+
Settings? settings = null
268+
) => RegisterParamless(
269+
functionTypeId,
270+
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
271+
settings
272+
);
253273

254274
// ** ASYNC W. RESULT AND WORKFLOW ** //
255275
public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(

Core/Cleipnir.ResilientFunctions/InnerAdapters/InnerToAsyncResultAdapters.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ public static Func<Unit, Workflow, Task<Result<Unit>>> ToInnerParamlessWithTaskR
5555
};
5656
}
5757

58+
public static Func<Unit, Workflow, Task<Result<Unit>>> ToInnerParamlessWithTaskResultReturn(Func<Task<Result<Unit>>> inner)
59+
{
60+
return async (_, _) =>
61+
{
62+
try
63+
{
64+
var result = await inner();
65+
return result;
66+
}
67+
catch (PostponeInvocationException exception) { return Postpone.Until(exception.PostponeUntil); }
68+
catch (SuspendInvocationException exception) { return Suspend.While(exception.ExpectedInterruptCount.Value); }
69+
catch (Exception exception) { return Fail.WithException(exception); }
70+
};
71+
}
72+
5873
public static Func<Unit, Workflow, Task<Result<Unit>>> ToInnerParamlessWithTaskResultReturn(Func<Workflow, Task<Result>> inner)
5974
{
6075
return async (_, workflow) =>

0 commit comments

Comments
 (0)