GithubHelp home page GithubHelp logo

Comments (3)

nordfjord avatar nordfjord commented on July 30, 2024 1

Imagine you've got a timer and want to cancel it when listeners stop:

function interval(ms: number) {
  const s = stream()
  let i = 0;
  const interval = setInterval(()=> s(i++), ms)
  s.end.map(()=> clearInterval(interval))
  return s
}

interval(1000)
  .pipe(take(4))
// 1-2-3-4

This can be extrapolated for arbitrary cleanup logic for e.g. web sockets

from flyd.

dehmer avatar dehmer commented on July 30, 2024

I assume take in the case must be aware of the additional protocol and has to actively close upstream interval when it's done. take probably also has to close itself so that an appropriate side-effect can be triggered. I this correct?

from flyd.

nordfjord avatar nordfjord commented on July 30, 2024

That sounds about right. Some of the built-in modules propagate ending downwards using a pattern like

const takeUntil = (term, src) =>
  flyd.endsOn(
    flyd.merge(term, src.end),
    flyd.combine((src, self) => {
      self(src());
    }, [src])
  );

from flyd.

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.