Skip to content

cszredwan/crazyObservable

Repository files navigation

crazyObservable

crazyObservable is a custom RxJS observable that act as a blueprint for streams of random emissions, that is, streams drawn from all possibilities of emmiting a predefined number of data over a predefined number of time steps (see [Marble diagram] bellow). This observable is intended to give a better approach to tackle problems like described in the following questions:

Marble diagram

The following Marble diagram shows a possible datastream obtained by a subscription to crazyObservable(16, 1000, 7) where 16 is the totalNumberOfEmissions, 1000 is the timeInterval (in milliseconds) and 7 is the totalNumberOfTimeIntervals.

Marble diagram of brazyObservable

Code example

The following code gives an example of how to use crazyObservables. Be sure to import discreteRandomAssignment.js to use crazyObservable.

var oneHourRandomTenHundredRequisition$ = crazyObservable(10000, 1000, 60 * 60);
// crazyObservable( totalNumberOfEmissions, timeInterval (miliseconds), totalNumberOfTimeIntervals )

let testComponent1 = oneHourRandomTenHundredRequisition$.subscribe({
next() { console.log("That's up to you!"); } ,
error() { console.log("An error have been encountered."); },
complete() { console.log("crazyObservable is garanteed to complete, unless your custom next() return an error}
});

Special Features

  • Note that calculations are done asyncronously and the number of emissions at each timestep is calculation on-the-fly.
  • In practice, complexity seems to grow linearly on most of parameters, but I am working working in a formal proof.

Proof

I will soon upload a for crazyObservable validity that relies in the discrete random assignment implemented here.

Future Work

I am up to refactoring this code to serve as a singleton service for Angular apps as soon as possible.

About

Custom RxJS observable that emits randomly a fixed number of data over a fixed number of time intervals.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published