Align single-shot memoization (#2546)

* Align single-shot memoization

* Small tweaks

* Test for delayed creates

* With actual sub

* Expand delay test

* Bump delay
This commit is contained in:
Jaco Greeff
2020-08-31 14:31:44 +02:00
committed by GitHub
parent dd52ea4b32
commit 2f5e2537a3
4 changed files with 79 additions and 68 deletions
+17 -2
View File
@@ -91,10 +91,25 @@ describe('Cached Observables', (): void => {
expect(observable2).not.toBe(observable1);
});
it('creates multiple observables for one-shots', (): void => {
it('creates single observables for subsequent one-shots', (): void => {
const observable1 = rpc.chain.getBlockHash(123);
const observable2 = rpc.chain.getBlockHash(123);
expect(observable2).not.toBe(observable1);
expect(observable2).toBe(observable1);
});
it('creates multiple observables for subsequent one-shots delayed', (done): void => {
const observable1 = rpc.chain.getBlockHash(123);
const sub = observable1.subscribe((): void => {
sub.unsubscribe();
});
expect(rpc.chain.getBlockHash(123)).toBe(observable1);
setTimeout((): void => {
expect(rpc.chain.getBlockHash(123)).not.toBe(observable1);
done();
}, 1000);
});
});