Skip to content

Commit

Permalink
Rename dissolve to cancel (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinresol committed Oct 4, 2018
1 parent c45b90d commit 93d2e35
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
23 changes: 12 additions & 11 deletions src/tink/core/Callback.hx
Expand Up @@ -53,7 +53,7 @@ abstract Callback<T>(T->Void) from (T->Void) {
}
}
private interface LinkObject {
function dissolve():Void;
function cancel():Void;
}

abstract CallbackLink(LinkObject) from LinkObject {
Expand All @@ -62,18 +62,19 @@ abstract CallbackLink(LinkObject) from LinkObject {
this = new SimpleLink(link);

public inline function cancel():Void
if (this != null) this.dissolve();

if (this != null) this.cancel();

@:deprecated('Use cancel() instead')
public inline function dissolve():Void
cancel();

static function noop() {}

@:to inline function toFunction():Void->Void
return if (this == null) noop else this.dissolve;
return if (this == null) noop else this.cancel;

@:to inline function toCallback<A>():Callback<A>
return function (_) this.dissolve();
return function (_) this.cancel();

@:from static inline function fromFunction(f:Void->Void)
return new CallbackLink(f);
Expand All @@ -82,7 +83,7 @@ abstract CallbackLink(LinkObject) from LinkObject {
return new LinkPair(a, b);

@:from static function fromMany(callbacks:Array<CallbackLink>)
return fromFunction(function () for (cb in callbacks) cb.dissolve());
return fromFunction(function () for (cb in callbacks) cb.cancel());
}

private class SimpleLink implements LinkObject {
Expand All @@ -91,7 +92,7 @@ private class SimpleLink implements LinkObject {
public inline function new(f)
this.f = f;

public inline function dissolve()
public inline function cancel()
if (f != null) {
f();
f = null;
Expand All @@ -108,11 +109,11 @@ private class LinkPair implements LinkObject {
this.b = b;
}

public function dissolve()
public function cancel()
if (!dissolved) {
dissolved = true;
a.dissolve();
b.dissolve();
a.cancel();
b.cancel();
a = null;
b = null;
}
Expand All @@ -138,7 +139,7 @@ private class ListCell<T> implements LinkObject {
cb = null;
}

public function dissolve()
public function cancel()
switch list {
case null:
case v: clear(); v.remove(this);
Expand Down
4 changes: 2 additions & 2 deletions src/tink/core/Promise.hx
Expand Up @@ -123,7 +123,7 @@ abstract Promise<T>(Surprise<T, Error>) from Surprise<T, Error> to Surprise<T, E

function done(o) {
if (links == null) sync = true;
else links.dissolve();
else links.cancel();
cb(o);
}

Expand Down Expand Up @@ -159,7 +159,7 @@ abstract Promise<T>(Surprise<T, Error>) from Surprise<T, Error> to Surprise<T, E
links = linkArray;

if (sync)
links.dissolve();
links.cancel();
}, lazy);

static public function inSequence<T>(a:Array<Promise<T>>):Promise<Array<T>> {
Expand Down
4 changes: 2 additions & 2 deletions src/tink/core/Signal.hx
Expand Up @@ -75,11 +75,11 @@ abstract Signal<T>(SignalObject<T>) from SignalObject<T> to SignalObject<T> {
link = this.handle(function (v) if (condition == null || condition(v)) {
ret.trigger(v);
if (link == null) immediate = true;
else link.dissolve();
else link.cancel();
});

if (immediate)
link.dissolve();
link.cancel();

return ret.asFuture();
}
Expand Down
16 changes: 8 additions & 8 deletions tests/Callbacks.hx
Expand Up @@ -51,8 +51,8 @@ class Callbacks extends Base {
public function testSimpleLink() {
var calls = 0;
var link:CallbackLink = function () calls++;
link.dissolve();
link.dissolve();
link.cancel();
link.cancel();
asserts.assert(calls == 1);
return asserts.done();
}
Expand All @@ -66,18 +66,18 @@ class Callbacks extends Base {
var link2:CallbackLink = function () { calls++; calls2++; }
var link = link1 & link2;

link.dissolve();
link.cancel();
asserts.assert(calls == 2);
asserts.assert(calls1 == 1);
asserts.assert(calls2 == 1);

link.dissolve();
link.cancel();
asserts.assert(calls == 2);

link1.dissolve();
link1.cancel();
asserts.assert(calls1 == 1);

link2.dissolve();
link2.cancel();
asserts.assert(calls2 == 1);
return asserts.done();
}
Expand All @@ -102,11 +102,11 @@ class Callbacks extends Base {
asserts.assert(calls1 == 1);
asserts.assert(calls2 == 1);

link1.dissolve();
link1.cancel();

asserts.assert(cb.length == 1);

link1.dissolve();
link1.cancel();

asserts.assert(cb.length == 1);

Expand Down
6 changes: 3 additions & 3 deletions tests/Futures.hx
Expand Up @@ -36,7 +36,7 @@ class Futures extends Base {
});

asserts.assert(1 == callbacks.length);
link1.dissolve();
link1.cancel();

trigger();

Expand Down Expand Up @@ -148,10 +148,10 @@ class Futures extends Base {

public function testNever() {
var f:Future<Int> = cast Future.NEVER;
f.handle(function () {}).dissolve();
f.handle(function () {}).cancel();
function foo<A>() {
var f:Future<A> = cast Future.NEVER;
f.handle(function () {}).dissolve();
f.handle(function () {}).cancel();
}
foo();
return asserts.done();
Expand Down
22 changes: 11 additions & 11 deletions tests/Signals.hx
Expand Up @@ -42,7 +42,7 @@ class Signals extends Base {
var link = s.handle(function () {});
asserts.assert(active);

link.dissolve();
link.cancel();
asserts.assert(!active);

link = s.handle(function () {});
Expand All @@ -51,10 +51,10 @@ class Signals extends Base {
var link2 = s.handle(function () {});
asserts.assert(active);

link.dissolve();
link.cancel();
asserts.assert(active);

link2.dissolve();
link2.cancel();
asserts.assert(!active);
return asserts.done();
}
Expand All @@ -80,12 +80,12 @@ class Signals extends Base {

asserts.assert(4 == calls);

link2.dissolve();
link2.cancel();

asserts.assert(1 == handlers1.getLength());
asserts.assert(1 == handlers2.getLength());

link1.dissolve();
link1.cancel();

asserts.assert(0 == handlers1.getLength());
asserts.assert(0 == handlers2.getLength());
Expand Down Expand Up @@ -114,12 +114,12 @@ class Signals extends Base {

asserts.assert(4 == calls);

link2.dissolve();
link2.cancel();

asserts.assert(1 == handlers1.getLength());
asserts.assert(1 == handlers2.getLength());

link1.dissolve();
link1.cancel();

asserts.assert(1 == handlers1.getLength());
asserts.assert(1 == handlers2.getLength());
Expand All @@ -146,11 +146,11 @@ class Signals extends Base {
asserts.assert(1 == mapCalls);
asserts.assert('foofoo' == last);

link2.dissolve();
link2.cancel();

asserts.assert(1 == handlers1.getLength());

link1.dissolve();
link1.cancel();

asserts.assert(1 == handlers1.getLength());
return asserts.done();
Expand All @@ -176,11 +176,11 @@ class Signals extends Base {
asserts.assert(2 == mapCalls);
asserts.assert('foofoo' == last);

link2.dissolve();
link2.cancel();

asserts.assert(1 == handlers1.getLength());

link1.dissolve();
link1.cancel();

asserts.assert(0 == handlers1.getLength());
return asserts.done();
Expand Down

0 comments on commit 93d2e35

Please sign in to comment.