Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify usage patterns of Task.run #75

Open
darioteixeira opened this issue Jun 19, 2022 · 1 comment
Open

Clarify usage patterns of Task.run #75

darioteixeira opened this issue Jun 19, 2022 · 1 comment

Comments

@darioteixeira
Copy link

I realise the library's API and documentation are still a work in progress, but currently it doesn't seem to fully leverage the type system to ensure proper usage. Case in point: function Task.parallel_for (and its siblings) will throw an exception unless invoked within a Task.run context, but nothing about its type suggests this. Suppose that instead the signatures for Task.run and Task.parallel_for were something along these lines, where context is an abstract type (actually internally the same as pool):

val run : pool -> (context -> 'a) -> 'a
val parallel_for : ?chunk_size:int -> start:int -> finish:int -> body:(int -> unit) -> context -> unit

This way it would be impossible to invoke Task.parallel_for outside a Task.run context.

Similarly, the current API and documentation is ambiguous regarding the intended usage patterns for Task.run: Should it invoked only once at the top-level, thus making its usage off-limits for libraries, for example?

@kayceesrk
Copy link
Contributor

kayceesrk commented Jun 19, 2022

The proposed solution won't work. You may store the context in a global ref and use it in a context without a Task.run in scope.

We shall aim to clarify the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants