Yeah, if it ain't broke.. don't fix it.
Anyways, I have a pretty decent set of changes:
Bugs
- Fixed memory leak in Stream
- Fixed situation where a promise could be rejected and resolved at the same time via deferred
- Worked around problem with Java and CSharp where the macro "whenall" function would error out on array types for some reason.
Changes
- link functions are now instance rather than static (less code, slightly faster, but minor)
- use the new (faster!) asap library for browser/node js, which should fix some of the weird slowdowns in newer v8.
- added more thrown errors for states that I think need to be treated as such (treating a stream "end" state similar to a promise "rejected" state... disallowing continued resolutions)
- Macro monadic do forms are moved to MacroPromise and MacroStream, etc.
New Features:
Stream has a new abstract form that I've been experimenting with. It treats the ">>" operator as the "then" method, and "||" as the "pipe" method. I think it makes things look a bit neater, but thought I would get some feedback.
E.g.:
var p = new promhx.PublicStream<String>();
var s:AbstractStream<String> = p;
var k = s >> function(x) { return x + ' foo';}
>> function(x) { return x + ' bar';}
|| function(x) { trace(x); return new promhx.Stream<Int>();}
$type(k); // promhx.abs.AbstractPromise<Int>;
p.resolve("baz");
// traces: baz foo bar
I got this notion from Juraj IIRC, I think he's done something similar and might have a trip report.
The other option is to override basic math/concatenation operators for promises and streams, and then provide "deferred" versions of them automatically.
E.g.:
var s :AbstractStream<String> = new Stream<String>();
var k = s + 'a string';
$type(k); // promhx.abs.AbstractPromise<String>;