Skip to content

Commit

Permalink
Catch 'Object has been destroyed' errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnovert committed Jan 21, 2018
1 parent 1a73938 commit 204b8ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 9 additions & 3 deletions modules/ipc/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ exports.init = function() {
// Register new listener
rxIpc.registerListener('rpc-channel', (event, method, params) => {
return Observable.create(observer => {

if (['restart-daemon'].includes(method)) {
daemon.restart(() => observer.next(true));
} else {
rpc.call(method, params, (error, response) => {
error ? observer.error(error) : observer.next(response || undefined);
try {
error ? observer.error(error) : observer.next(response || undefined);
} catch (err) {
if (err.message == 'Object has been destroyed') {
// suppress error
} else {
log.error(err);
}
}
});
}

});
});
}
11 changes: 3 additions & 8 deletions src/app/wallet/overview/widgets/coldstake/coldstake.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, OnDestroy } from '@angular/core';
import { MatDialog } from '@angular/material';
import { Log } from 'ng2-logger';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

import { ModalsService } from 'app/modals/modals.service';
import { RpcService } from 'app/core/rpc/rpc.module';
Expand All @@ -26,7 +25,7 @@ export class ColdstakeComponent implements OnDestroy {
public encryptionStatus: string = 'Locked';
private progress: Amount = new Amount(0, 2);
get coldstakeProgress(): number { return this.progress.getAmount() }
private obsprogress: Subscription = undefined;
private destroyed: boolean = false;

hotstakingamount: number = 0.0;
coldstakingamount: number = 0.0;
Expand All @@ -45,11 +44,9 @@ export class ColdstakeComponent implements OnDestroy {
this._rpc.state.observe('ui:coldstaking:stake')
.subscribe(status => this.stakingTowardsCold = status);

this.obsprogress = this._rpc.state.observe('blocks').throttle(val => Observable.interval(30000/*ms*/))
this._rpc.state.observe('blocks').takeWhile(() => !this.destroyed).throttle(val => Observable.interval(10000/*ms*/))
.subscribe(block => this.rpc_progress());

// TODO: move to coldstaking service
this.rpc_progress();
}

private rpc_progress(): void {
Expand All @@ -62,9 +59,7 @@ export class ColdstakeComponent implements OnDestroy {
}

ngOnDestroy() {
if (this.obsprogress) {
this.obsprogress.unsubscribe();
}
this.destroyed = true;
}

private stakingStatus() {
Expand Down

0 comments on commit 204b8ca

Please sign in to comment.