Skip to content

Commit

Permalink
Fix unit inference take2 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd authored Nov 9, 2023
1 parent 05f041e commit 5c745d0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/IcedTasks/CancellableTask.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module CancellableTasks =
member inline _.Source
(x: CancellationToken -> Task<_>)
: CancellationToken -> Awaiter<TaskAwaiter<_>, _> =
fun ct -> (x ct).GetAwaiter()
fun ct -> Awaitable.GetTaskAwaiter(x ct)

member inline this.MergeSources
(
Expand Down
47 changes: 39 additions & 8 deletions src/IcedTasks/CancellableTaskBuilderBase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ module CancellableTaskBase =
[<InlineIfLambda>] getAwaiter: CancellationToken -> 'Awaiter,
continuation:
('TResult1 -> CancellableTaskBaseCode<'TOverall, 'TResult2, 'Builder>)
) =
) : CancellableTaskBaseCode<'TOverall, 'TResult2, 'Builder> =

CancellableTaskBaseCode<'TOverall, _, _>(fun sm ->
CancellableTaskBaseCode<'TOverall, 'TResult2, 'Builder>(fun sm ->
if __useResumableCode then
//-- RESUMABLE CODE START
sm.Data.ThrowIfCancellationRequested()
Expand Down Expand Up @@ -679,17 +679,46 @@ module CancellableTaskBase =
///
/// <remarks>This turns a Task&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>CancellationToken -> 'Awaiter</returns>
/// <returns>'Awaiter</returns>
member inline _.Source(task: TaskAwaiter<'T>) : Awaiter<TaskAwaiter<'T>, 'T> = task

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a Task&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>'Awaiter</returns>
member inline _.Source(task: Task<'T>) : Awaiter<TaskAwaiter<'T>, 'T> =
task.GetAwaiter()
Awaitable.GetTaskAwaiter task

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a ColdTask&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>CancellationToken -> 'Awaiter</returns>
member inline _.Source([<InlineIfLambda>] task: unit -> Task<'TResult1>) =
(fun (ct: CancellationToken) -> (task ()).GetAwaiter())
member inline _.Source
([<InlineIfLambda>] task: unit -> TaskAwaiter<'T>)
: CancellationToken -> Awaiter<TaskAwaiter<'T>, 'T> =
(fun (ct: CancellationToken) -> (task ()))

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a ColdTask&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>CancellationToken -> 'Awaiter</returns>
member inline _.Source
([<InlineIfLambda>] task: unit -> Task<'T>)
: CancellationToken -> Awaiter<TaskAwaiter<'T>, 'T> =
(fun (ct: CancellationToken) -> Awaitable.GetTaskAwaiter(task ()))

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a CancellableTask&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>CancellationToken -> 'Awaiter</returns>
member inline _.Source
([<InlineIfLambda>] task: CancellationToken -> TaskAwaiter<'T>)
: CancellationToken -> Awaiter<TaskAwaiter<'T>, 'T> =
(fun ct -> (task ct))

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
Expand All @@ -699,12 +728,14 @@ module CancellableTaskBase =
member inline _.Source
([<InlineIfLambda>] task: CancellationToken -> Task<'T>)
: CancellationToken -> Awaiter<TaskAwaiter<'T>, 'T> =
(fun ct -> (task ct).GetAwaiter())
(fun ct -> Awaitable.GetTaskAwaiter(task ct))

/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
/// <remarks>This turns a Async&lt;'T&gt; into a CancellationToken -> 'Awaiter.</remarks>
///
/// <returns>CancellationToken -> 'Awaiter</returns>
member inline this.Source(computation: Async<'TResult1>) =
member inline this.Source
(computation: Async<'T>)
: CancellationToken -> Awaiter<TaskAwaiter<'T>, 'T> =
this.Source(Async.AsCancellableTask(computation))
2 changes: 1 addition & 1 deletion src/IcedTasks/TaskBuilderBase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ module TaskBase =
/// <remarks>This turns a Task&lt;'T&gt; into a 'Awaiter.</remarks>
///
/// <returns>'Awaiter</returns>
member inline _.Source(task: Task<'T>) = task.GetAwaiter()
member inline _.Source(task: Task<'T>) = Awaitable.GetTaskAwaiter task

/// <summary>Allows the computation expression to turn other types into 'Awaiter</summary>
///
Expand Down

0 comments on commit 5c745d0

Please sign in to comment.