Giter Site home page Giter Site logo

Comments (5)

victimsnino avatar victimsnino commented on May 24, 2024 2

@mincequi,
To be honest, you can achieve requested behavior with something like this:

#include <rpp/rpp.hpp>
#include <iostream>

auto sample_with_time_oversampling(rpp::schedulers::duration period, const auto& scheduler)
{
    return [=](const auto& observable)
    {
        return rpp::source::interval(period, scheduler)
                .with_latest_from([](const auto&, const auto& v) { return v; }, observable);
    };
}


int main()
{
    auto start = rpp::schedulers::clock_type::now();
    rpp::source::interval(std::chrono::milliseconds{1000}, rpp::schedulers::trampoline{})
            .op(sample_with_time_oversampling(std::chrono::milliseconds{500},
                                              rpp::schedulers::trampoline{}))
    .take(10)
            .subscribe([&](size_t v)
            {
                std::cout << "get value " << v << " at " << std::chrono::duration_cast<std::chrono::milliseconds>(rpp::schedulers::clock_type::now() - start) << std::endl;
            });
    return 0;
}

Output:

get value 0 at 1008ms
get value 0 at 1506ms
get value 1 at 2010ms
get value 1 at 2504ms
get value 2 at 3004ms
get value 2 at 3512ms
get value 3 at 4005ms
get value 3 at 4513ms
get value 4 at 5008ms
get value 4 at 5502ms

from reactiveplusplus.

victimsnino avatar victimsnino commented on May 24, 2024 1

Ohh, i see.

I have both, but not time-based versions. I've created issues for them
#312
#313

from reactiveplusplus.

victimsnino avatar victimsnino commented on May 24, 2024

Hi @mincequi,

I'm not sure if it is expected behavior... "demo" for this operator from ReactiveX proves that no any additional emission in case of oversampling:

image

Same about RxJava. In place of emitting value it "clears" old value, so it is not possible that operator emits same value twice:

void emit() 
{
  T value = getAndSet(null);
  if (value != null) {
      downstream.onNext(value);
}

source

from reactiveplusplus.

mincequi avatar mincequi commented on May 24, 2024

Hi @victimsnino ,
yes, apparently the official behaviour is only undersampling. (like it is done in rxJava).

For that reason, i would need a time based window or time based buffer operator to tackle my desired behaviour.

So my question is, do you plan to realise buffer or window operator any time soon?
This is probably my last request for now :)

from reactiveplusplus.

victimsnino avatar victimsnino commented on May 24, 2024

Closing due to inactivity

from reactiveplusplus.

Related Issues (20)

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.