mostjs / hold Goto Github PK
View Code? Open in Web Editor NEWDeliver the most recently seen event to new observers
License: MIT License
Deliver the most recently seen event to new observers
License: MIT License
Basically what the title says :)
From the architecture wiki:
"A producer source must never produce an event in the same call stack as its run method is called. It must begin producing items asynchronously."
The holdAdd()
method is currently violating this policy, resulting in errors in certain edge cases.
https://github.com/mostjs/hold/blob/master/src/index.js#L36
To elaborate on the error, in some cases when a single source exists at two places in a composed stream (potentially via most-proxy), it is possible for a sink constructor call to be on the stack, call its upstream source.run()
, and then to end up on the stack a second time for an upstream run
call. If the upstream run
call then tries to bypass the scheduler and emit an event synchronously, without allowing the run
stack to finish first, then because event
and dispose
can both be called in the same stack, the sink whose constructor is still on the stack can have dispose
called before its disposable
property has finished being assigned, resulting in the error:
TypeError: Cannot read property 'dispose' of undefined
So, I came across a strange behavior while messing around with @most/hold. For the example, consider the following function which produces a infinite stream of numbers (starting with 0) according to a given time period:
const interval = period => filter(x => x !== -1, scan((x, y) => x + y, -1, constant(1, skip(1, periodic(period)))));
Well, now, consider the following code:
//let testHold = hold(interval(2000));
let testHold = multicast(interval(2000));
runEffects(tap(console.log, take(3, testHold)), newDefaultScheduler());
setTimeout(()=>{
runEffects(tap(console.log, take(11, testHold)), newDefaultScheduler());
}, 4500);
With multicast, the code works as expected, printing: 0, 1, 2, 2, 3, 4, 5, ...
But, with hold, it acts strangely, printing: 0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6
I personally was expecting something more like 0, 1, 1, 2, 2, 3, 4, 5, ....
In other words, the second run should access the second emission (last from first run at time 4000 milliseconds), print one more number (2) together with the first run (the last number taken from the first run), and keep printing the reaming sequence.
Additionally, the program keeps hanging after the last two 6
With a jsnext:main and module in package.json, most.js works much better together with packaging tools such as Rollup and Webpack. And you get glorious tree shaking as a bonus.
More info: https://github.com/rollup/rollup/wiki/jsnext:main
Update the peer dependency on most
to the latest version 0.17.1
So other packages that depend on this library can update to 0.17.1 of most
"Deliver the most recently seen event to each new observer the instant it begins observing"
This sentence could make someone think the observer will observe a value synchronously when it doesn't ? (setTimeout(fn, 0) so could be anywhere between 1 and 10ms)
Hey, guys!
I installed @most/hold last version (3.0.0) and for some reason the type definition file seems to be out-of-date. In this way, it raises the following error while building my code:
node_modules/@most/hold/type-definitions/hold.d.ts:1:59 - error TS2307: Cannot find module 'most'.
1 import {Stream, Source, Sink, Scheduler, Disposable} from "most";
I've checked the commits, and the above import was in fact present in hold.d.ts until the commit 15ee95c
@most/hold still includes a package.json that has a 0.19.7 peerDependency. The latest on github is at 1.0.0, can this be republished?
Hi, @briancavalier!
While working on #34 I ran into various issues related to Flow. Flow has poor tooling and IDE support (with almost no hints in IDE), I was able to run typechecking only with npm run test:flow
.
I think migrating to TypeScript which has a way better IDE support and tooling would provide the best developer experience.
If you approve I would open a PR with migration to the most strict typescript configuration and with transparent changes of build steps.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.