-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Expose non monadic version of Future #44
Comments
ℹ️ I'm working on this. |
I'm looking into developing this as its own package, extending Fluture with an optional Parallel structure. Some of Flutures core functionality will also be separated out to serve as a base for both packages. |
@Avaq why? So you are planning to have 3 repos like this?:
|
In writing a detailed response about my reasons, I realized there may be some issues with this approach (circular dependencies, shared code). I'm going to drop the idea, and keep it in the same package. |
After discussing this offline, here is what we came to: As there is Concurrently in haskell: newtype Concurrently a = Concurrently { runConcurrently :: IO a }
instance Functor Concurrently where
fmap f (Concurrently a) = Concurrently $ f <$> a
instance Applicative Concurrently where
pure = Concurrently . return
Concurrently fs <*> Concurrently as =
Concurrently $ (\(f, a) -> f a) <$> concurrently fs as
instance Alternative Concurrently where
empty = Concurrently $ forever (threadDelay maxBound)
Concurrently as <|> Concurrently bs =
Concurrently $ either id id <$> race as bs We could have something like this: const mkConcurrently = (TaskRep, concurrently, race, zero) => {
const Concurrently = daggy.tagged('run')
Concurrently[fl.zero] = zero
Concurrently[fl.of] = (a) => Concurrently(TaskRep[fl.of](a))
Object.assign(Concurrently.prototype, {
[fl.map](f) {
return Concurrently(this.run[fl.map](f))
},
[fl.ap](a) {
return Concurrently(concurrently(this.run,a))
},
[fl.alt](a) {
return Concurrently(race(this.run, a))
},
})
return Concurrently
} Which could be used with any Task/Future/whatever. Example with Fluture: const Par = mkConcurrently(
Fluture,
(a,b) => a.par(b),
(a,b) => a.race(b),
Fluture.never
)
Par(Fluture.after(300, 1))[fl.alt](Par(Future.of(2)))
.run.fork(log, log) |
I think using names in spirit of purescript-parallel would be better: -const Concurrently = daggy.tagged('run')
+const Parallel = daggy.tagged('sequential') Par(Fluture.after(300, 1))[fl.alt](Par(Future.of(2)))
- .run.fork(log, log)
+ .sequential.fork(log, log) |
I created https://github.com/fluture-js/concurrify for this purpose. I'm working on the implementation now. Your thoughts? |
That's nice! what you think about moving that to FantasyLand, as fantasy-concurrify for example? |
I'm creating it with the design decisions made for Fluture in mind. I'm not sure if it's too opinionated to host under FantasyLand (eg; the inclusion of |
The next step, I think, would be to depend on concurrify and expose |
Adds the following functions: * Future.Par :: (Applicative f, Alternative (m f)) => f a -> m f a * Adds Future.seq :: Applicative f => Par f a -> f a * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following functions: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: () -> Future a a Closes #44
Adds the following exports: * Future.Par :: Future a b -> ConcurrentFuture a b * Future.seq :: ConcurrentFuture a b -> Future a b * Future.never :: Future a a Closes #44
It will be nice to expose non monadic version of Future for which
ap
would be parallel.This version could also implement Alternative where
alt
would berace
The text was updated successfully, but these errors were encountered: