Skip to content

Instantly share code, notes, and snippets.

@alebianco
Created August 19, 2015 11:08
Show Gist options
  • Save alebianco/5a4ab56a6934bf3e2ed2 to your computer and use it in GitHub Desktop.
Save alebianco/5a4ab56a6934bf3e2ed2 to your computer and use it in GitHub Desktop.
Promhx memory leak
package ;
import promhx.Deferred;
import promhx.Stream;
import promhx.deferred.DeferredStream;
@:expose("game")
@:keep
class Main {
public static var instance:Main;
public var messages:Deferred<Int>;
public var stream:Stream<Int>;
public var handler:Stream<Void>;
public function new() {
messages = new Deferred<Int>();
stream = messages.stream();
}
public function attach():Void {
handler = stream.then(onMessage);
}
public function detach():Void {
stream.detachStream(handler);
// untyped stream._end_promise._update = [];
handler = null;
}
public function resolve(value:Int):Void {
messages.resolve(value);
}
public function loop(value:Int):Void {
attach();
resolve(value);
detach();
}
function onMessage(value:Int):Void {
trace(value);
}
static function main() {
instance = new Main();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment