Code Monkey home page Code Monkey logo

monix.io's Introduction

Monix

Asynchronous, Reactive Programming for Scala and Scala.js.

monix Scala version support

Build Gitter Discord

Overview

Monix is a high-performance Scala / Scala.js library for composing asynchronous, event-based programs.

It started as a proper implementation of ReactiveX, with stronger functional programming influences and designed from the ground up for back-pressure and made to interact cleanly with Scala's standard library, compatible out-of-the-box with the Reactive Streams protocol. It then expanded to include abstractions for suspending side effects and for resource handling, and is one of the parents and implementors of Cats Effect.

A Typelevel project, Monix proudly exemplifies pure, typeful, functional programming in Scala, while being pragmatic, and making no compromise on performance.

Highlights:

  • exposes the kick-ass Observable, Iterant, Task, IO[E, A], and Coeval data types, along with all the support they need
  • modular, split into multiple sub-projects, only use what you need
  • designed for true asynchronicity, running on both the JVM and Scala.js
  • excellent test coverage, code quality, and API documentation as a primary project policy

Usage

Library dependency (sbt)

For the stable release (compatible with Cats, and Cats-Effect 2.x):

libraryDependencies += "io.monix" %% "monix" % "3.4.1"

Sub-projects

Monix 3.x is modular by design. See the sub-modules graph:

Sub-modules graph

You can pick and choose:

  • monix-execution exposes the low-level execution environment, or more precisely Scheduler, Cancelable, Atomic, Local, CancelableFuture and Future based abstractions from monix-catnap.
  • monix-catnap exposes pure abstractions built on top of the Cats-Effect type classes; depends on monix-execution, Cats 1.x and Cats-Effect
  • monix-eval exposes Task, Coeval; depends on monix-execution
  • monix-reactive exposes Observable for modeling reactive, push-based streams with back-pressure; depends on monix-eval
  • monix-tail exposes Iterant streams for purely functional pull based streaming; depends on monix-eval and makes heavy use of Cats-Effect
  • monix provides all of the above

Documentation

See:

API Documentation:

(contributions are welcome)

Related:

Contributing

The Monix project welcomes contributions from anybody wishing to participate. You must license all code or documentation provided with the Apache License 2.0, see LICENSE.txt.

You must follow the Scala Code of Conduct when discussing Monix on GitHub, Gitter channel, or other venues.

Feel free to open an issue if you notice a bug, have an idea for a feature, or have a question about the code. Pull requests are also gladly accepted. For more information, check out the contributor guide.

If you'd like to donate in order to help with ongoing maintenance:

Adopters

Here's a (non-exhaustive) list of companies that use Monix in production. Don't see yours? Submit a PR ❤️

License

All code in this repository is licensed under the Apache License, Version 2.0. See LICENSE.

monix.io's People

Contributors

adrielvelazquez avatar alexandru avatar almendar avatar ankitson avatar aoprisan avatar avasil avatar cranst0n avatar dependabot[bot] avatar dtuttleo avatar fedor-malyshkin avatar gabro avatar gautamjain9615 avatar ivanyu avatar jozic avatar justinhj avatar kanak avatar kell18 avatar khayuenkam avatar macalinao avatar milenkara avatar ngbinh avatar ochrons avatar olivierblanvillain avatar paualarco avatar peterneyens avatar peterperhac avatar pierangeloc avatar purijatin avatar rberenguel avatar zelenya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

monix.io's Issues

Compilation problem in example code (Consumer chapter, Introduction section)

Hi!

I was reading Monix docs (great work btw), and I think I've found a small bug in the example code. In the 'Consumer' chapter, 'Introduction' section we have:

val sumConsumer = Consumer.foldLeft[Long,Long](Coeval(0L))(_ + _)

But the compiler complains:

[error]  found   : monix.eval.Coeval[Long]
[error]  required: Long
[error]   val sumConsumer: Consumer[Long,Long] = Consumer.foldLeft[Long,Long](Coeval(0L))(_ + _

Replacing Coeval(0L) with just 0L solves the problem:

val sumConsumer = Consumer.foldLeft[Long,Long](0L)(_ + _)

Hope it helps! And contragulations for your great work :)

Documentation TODO for 3.x

I hope this is OK, but I wanted to capture task ideas from @alexandru and @Avasil in #28 (comment) in a more visible place and also add a checklist.

  • Observable
  • Iterant (lots of documentation in Scaladocs)
  • Scheduler
    • clockRealtime / clockMonotonic
    • TracingScheduler
  • new Task features:
    • cancelable
    • uncancelable
    • onCancelRaiseError
    • bracket
    • start + cancel + Fiber
    • racePair
    • onErrorRestartLoop
  • TaskLocal
  • cats-effect integration
    • Timer

Docs for making repeated requests with Observable

Copied from gitter... Thanks @alexandru

@theamytran for repeated HTTP requests, it’s a very simple job, you can simply do …

// Continuous
Observable.repeat(()).mapFuture(_ => createFuture())
// Request every 1 second
Observable.interval(1.second).mapFuture(_ => createFuture())

Observable.repeat(()).mapTask(_ => createTask())
// Request every 1 second
Observable.interval(1.second).mapTask(_ => createTask())

// There’s also good-old flatMap / concatMap
Observable.interval(1.second).concatMap(_ => Observable.fromTask(myTask))
Observable.interval(1.second).concatMap(_ => Observable.fromFuture(myFuture()))

Note there's intervalWithFixedDelay and intervalAtFixedRate. And these operators, along with these mapFuture, mapTask, concatMap, mapAsync are applying back-pressure, so you won’t have multiple requests running in parallel, unless you want it (see mapAsync(paralellism=4))
@theamytran @a-reisberg when publishing into a PublishSubject, note that their back-pressure contract needs to be respected and that back-pressure contract also implies doing synchronization, in case you want to call onNext from multiple sources / threads. If you don’t want to deal with back-pressure or with concurency, one needs to use a ConcurrentSubject.publish instead, which place a concurrent buffer in front.
@theamytran if you don’t have a buffer (e.g. ConcurrentSubject, Pipe.multicast or Observable.create) and want to push straight into a simple Observer / Subscriber / Subject, then the back-pressure must be upholded. See the docs on that: https://monix.io/docs/2x/reactive/observers.html#feeding-an-observer

Improve 2.x documentation redirection

If we google Monix docs, e.g. monix task parallelism the first results are Monix 2.x
We get a notification to go to latest docs but if we click there we are redirected to its main page.

Would be cool if we could redirect directly to specific section (in this case parallelism) when possible instead of main page.

Inconsistency w.r.t Task#executeOn() documentation

When try out the code on https://github.com/monix/monix.io/blame/master/_docs/3x/eval/task.md#L599-L639 I see no difference between the two case with or without the asyncBoundary call.

In other words, it seems that now only the forked Task runs in the Scheduler.io() and the onFinish reverts to a thread from the default Scheduler.

Here's what I'm seeing in Ammonite:

@ val cancelable = {
    source.flatMap(_ => forked)
      .doOnFinish(_ => onFinish)
      .runToFuture
  }
Running on thread: main
Running on thread: my-io-592
Ends on thread: scala-execution-context-global-485
cancelable: monix.execution.CancelableFuture[Unit] = Async(Future(Success(())), monix.eval.internal.TaskConnection$Impl$$anon$1@1a799c73)

 @ val cancelable = {
    source.flatMap(_ => forked)
      .asyncBoundary
      .doOnFinish(_ => onFinish)
      .runToFuture
  }
Running on thread: main
Running on thread: my-io-592
Ends on thread: scala-execution-context-global-485
cancelable: monix.execution.CancelableFuture[Unit] = Async(Future(<not completed>), monix.eval.internal.TaskConnection$Impl$$anon$1@2d3c799e)


Is there something I'm missing? Or has there been a change in behavior since this was written?

ScalaFiddle example in 'Javascript Event Listeners' requires adding Monix library

Hi,

In the Javascript Event Listeners chapter there is a link to an example in ScalaFiddle. Unfortunately when visiting the page the example does not compile because the Monix library is not included automatically. The user can solve the problem by including the library manually.

I think that if the author of the ScalaFiddle page (@alexandru I believe) adds the library then users visiting the page will have it loaded automatically (I did that in a fork of the ScalaFiddle example that seems to run ok without any user intervention).

Best,

Improve documentation for 3.x

Some documentations are unclear - the most noticeable are the missing usages of the word "the", and in general others are unclear in the way the sentence is constructed.

Use compile-only checking

We can use mdoc:compile-only for code snippets. This should speed up the building of the site.

I see no reason for generating output, because it's slow and I've never seen the need for it, other than for simulating repl sessions, but those are awkward when copy/pasting, as you're copy/pasting the output as well. If we need output, we can add it manually in comments. If we need types, we can add them explicitly.

See scalameta/mdoc#366

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.