GithubHelp home page GithubHelp logo

proxy's People

Contributors

brandonpayton avatar tylors avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

proxy's Issues

Bug: proxy continues emitting events to disposed observer

I have a small bit of code in which I'm using a proxy:

function proxy(initial) {
  const {attach, stream} = makeProxy();
  return [stream.startWith(initial), attach];
}

export default function flatScan(f, initial) {
  return stream => {
    const [proxyState$, fulfill] = proxy(initial);
    const state$ = most.just(proxyState$).join(); // prevent proxy disposal bug
    const initialize = (x, state) => f(state, x, state$);
    const nextState$ = sample(initialize, stream, state$)
      .join()
      .thru(fn$ => sample((fn, state) => fn(state), fn$, state$))
      .startWith(initial)
      .multicast();
    fulfill(nextState$);
    return state$;
  };
}

Notice the commented line where I'm wrapping the proxy stream in another stream and then flattening it again. If I don't do this, and a second observer attaches to the proxy before the previous observer has disposed itself, then the original observer will still try to call dispose as it should, but the proxy will continue emitting events to that observer's sink, even after disposal. Somehow wrapping the proxy in another dummy operator solves the problem.

If you need an active use case in order to figure this out, let me know and I'll help you set up a working copy of my project so you can see it happening.

Stack overflow?

I've tried several ways to close the cycle with Proxy and they all seem to result in a stack overflow. Perhaps this sets up an infinite loop in the stream control logic?

This example counts to 5 the hard way, but it's a good example of the process I'm trying to model (shutting down a harmonic oscillator when it comes to rest). y$ emits a single true when the accumulated sum reaches 15. Closed-loop this would shut x$ down.

When the attach line is commented out you can see this in the console log. When it not commented out Chrome just sits there for a few seconds until devtools disconnects. I presume this crash is from the stack filling up with an endless stream of handshaking.

import { proxy }     from 'most-proxy'
import { periodic }  from 'most'

const trigger$ = periodic(1000, 1)
  .scan( (s, t) => s + t, 0)
  .take(10)

const { stream: yProxy$, attach: attachY } = proxy()

const x$ = trigger$.until(yProxy$)

const y$ = x$
  .scan( (s, x) => s + x, 0 )
  .map( sum => sum >= 15)
  .filter( b => b )
  .skipRepeats()

attachY(y$)

x$.observe( x => console.log(x))
y$.observe( x => console.log(x))

[edit] - Perhaps some sort of air-gap or break in the handshaking protocols is needed in the proxy stream to make the stream graph appear acyclic to the scheduler?

npm install fails on typescript error

Released code works fine, but when I downloaded the repo (to update the most version number in package.json) and ran npm install I got a whole bunch of errors like this:

node_modules/most/type-definitions/most.d.ts(7,72): error TS2304: Cannot find name 'Promise'.

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.