fsprojects / FSharp.Control.TaskSeq

A computation expression and module for seamless working with IAsyncEnumerable<'T> as if it is just another sequence
MIT License
93 stars 8 forks source link

Interoperating with CancellableTasks #78

Open dsyme opened 2 years ago

dsyme commented 2 years ago

While writing #77 I realised it would be logical to allow this TaskSeq thing to interoperate with a standard CancellableTask, that is

taskSeq {
    let! res = cancellableTask { ... }
    ...
}

which would pass the CancellationToken governing the iteration of the TaskSeq to the Cancellable task. This would give robust cancellation token passing through the overall computation.

Under the alternative long term strategy in #77 this would be the same as

asyncSeq {
    let! res = async2 { ... } // re-implemented F# async
    ...
}

because F# cancellableTask and async2 are more or less the same thing.

This would mean bringing a CancellableTask into this library from IcedTasks, which may be a good thing.

abelbraaksma commented 2 years ago

This would mean bringing a CancellableTask into this library from IcedTasks, which may be a good thing.

Hmm, yes. But then the top lib name of TaskSeq should be reconsidered, as the namespace will be hosting tasks and task sequences.

Maybe just FSharp.Control.Tasks and turn it into a collection of all of our wishlist in one place? I.e., cancellable task, parallel task and delayed tasks from IcedTasks and TaskSeq, perhaps later AsyncSeq as well? And then should we include the extremely useful FsToolkit taskResult and taskOption and the like?

Many questions and strategies possible... Though the idea of a "single stop shop" for all (or most) of task/async related stuff is appealing.

dsyme commented 2 years ago

Yes for the project and nuget something like FSharp.Control.TaskExtras may make sense

We can think it over a bit more but I guess it's OK to go for task/cancellableTask/taskSeq for now.

I'll think about whether it's possible to do an overall revamp for F#8, tailcalls etc too. If we did there would be no harm in a rename then.

abelbraaksma commented 1 year ago

@dsyme, see linked issue by @bartelink, #128. It's now a good time as any to discuss the scope of Task extensions and landing it. It appears that other libraries also yearn for a small, useful extension library.

Not exactly the same as what we discussed here, but this could be a precursor to unifying these efforts at some point.