Skip to content

Commit

Permalink
Add tests for cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl committed Jul 1, 2020
1 parent c26f688 commit e4bdd7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions __tests__/TestFuture.re
Expand Up @@ -464,4 +464,21 @@ describe("Future cancellation", () => {
)
|> ignore;
});
test("Dismisses callbacks for already cancelled Future", () => {
let counter = ref(0);
let future = Future.make(_resolve => None);
future->Future.cancel;
future->Future.get(_ => incr(counter));
expect(counter.contents) |> toBe(0);
});
test("Cancel doesn't get called after resolve", () => {
let counter = ref(0);
let future =
Future.make(resolve => {
resolve(0);
Some(() => incr(counter));
});
future->Future.cancel;
expect(counter.contents) |> toBe(0);
});
});
2 changes: 1 addition & 1 deletion src/Future.re
Expand Up @@ -86,7 +86,7 @@ let make =
};

let cancel = (Future(getFunc, _)) => {
let Cancel(cancel) = getFunc(_ => ());
let Cancel(cancel) = getFunc(noop);
cancel();
};

Expand Down

0 comments on commit e4bdd7e

Please sign in to comment.