You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These methods point to a more general concept — that of a "properties bag" that have to do with the "environment". These are used to inject properties, for example in Observable, such that whatever run-loop we are describing, the implementation knows how to deal with fairness concerns, or how to log exceptions.
However, it's not a perfect abstraction. For example, in Monix version 3.x, executing a Task requires Task.Options:
Complicating the picture is Observable, which, in its implementation, ends up executing Task references. For example, this method is forced to use a default Task.Options, as there's no way to inject it (Observable has no notion of Task.Options):
Wouldn't it be cool if we could use Scheduler for the dependency injection of stuff provided by the “environment”? Dependency injection for necessary utilities and resources that are commonly application-wide and part of the environment, such as logging, or metrics.
Case Study: Akka Streams
An example of something similar is the Attributes from Akka Streams. These Attributes in Akka Streams are used to override default behavior. You can, for example, override the buffers that Akka Streams uses on async boundaries:
importAttributes._valnestedSource=Source.single(0).map(_ +1).named("nestedSource") // Wrap, no inputBuffer setvalnestedFlow=Flow[Int]
.filter(_ !=0)
.via(Flow[Int].map(_ -2).withAttributes(inputBuffer(4, 4))) // override
.named("nestedFlow") // Wrap, no inputBuffer setvalnestedSink=
nestedFlow
.to(Sink.fold(0)(_ + _)) // wire an atomic sink to the nestedFlow
.withAttributes(name("nestedSink") and inputBuffer(3, 3)) // override
We're using TypeInfo tags from monix-newtypes, as this is conceptually a Map[String, Any], but we need to make it type-safe. Our keys have to be a type descriptor. And we also require support for "newtypes".
Currently, the Scheduler interface has these methods:
These methods point to a more general concept — that of a "properties bag" that have to do with the "environment". These are used to inject properties, for example in
Observable
, such that whatever run-loop we are describing, the implementation knows how to deal with fairness concerns, or how to log exceptions.However, it's not a perfect abstraction. For example, in Monix version 3.x, executing a
Task
requiresTask.Options
:Again, we have run-loop specific options, but this time the options are specific to
Task
. And soTask
then has methods like these:Complicating the picture is
Observable
, which, in its implementation, ends up executingTask
references. For example, this method is forced to use a defaultTask.Options
, as there's no way to inject it (Observable
has no notion ofTask.Options
):In other words,
Scheduler
isn't enough. But it should be, otherwise the integration withObservable
(or similar) isn't good.There's more —
Scheduler
could be used for all kinds of dependency injection. Consider the currentTask.deferAction
:Wouldn't it be cool if we could use
Scheduler
for the dependency injection of stuff provided by the “environment”? Dependency injection for necessary utilities and resources that are commonly application-wide and part of the environment, such as logging, or metrics.Case Study: Akka Streams
An example of something similar is the Attributes from Akka Streams. These
Attributes
in Akka Streams are used to override default behavior. You can, for example, override the buffers that Akka Streams uses on async boundaries:Attributes
is a data structure like this:So it's a list of attributes, where the attributes themselves are defined like:
Proposed solution
We need something similar to Akka Streams, but preferably more type-safe.
I'm thinking that we need a new data-structure:
We're using TypeInfo tags from
monix-newtypes
, as this is conceptually aMap[String, Any]
, but we need to make it type-safe. Our keys have to be a type descriptor. And we also require support for "newtypes".Then
Scheduler
could have this API:And, if, for example, we need
Task.Options
for the execution ofTask
, we could just do:The text was updated successfully, but these errors were encountered: