Skip to content

Commit

Permalink
Switch back to getter/setter for standby
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Sep 11, 2022
1 parent a02d471 commit ee26730
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/polling/src/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class Poll<T = any, U = any, V extends string = 'standby'>
* @param options - The poll instantiation options.
*/
constructor(options: Poll.IOptions<T, U, V>) {
this.standby = options.standby || Private.DEFAULT_STANDBY;
this._factory = options.factory;
this._linger = options.linger ?? Private.DEFAULT_LINGER;
this._standby = options.standby || Private.DEFAULT_STANDBY;
this._state = { ...Private.DEFAULT_STATE, timestamp: new Date().getTime() };

// Normalize poll frequency `max` to be the greater of
Expand Down Expand Up @@ -121,7 +121,16 @@ export class Poll<T = any, U = any, V extends string = 'standby'>
/**
* Indicates when the poll switches to standby.
*/
public standby: Poll.Standby | (() => boolean | Poll.Standby);
get standby(): Poll.Standby | (() => boolean | Poll.Standby) {
return this._standby;
}
set standby(standby: Poll.Standby | (() => boolean | Poll.Standby)) {
if (this.isDisposed || this.standby === standby) {
return;
}

this._standby = standby;
}

/**
* The poll state, which is the content of the current poll tick.
Expand Down Expand Up @@ -343,6 +352,7 @@ export class Poll<T = any, U = any, V extends string = 'standby'>
private _handle: ScheduleHandle = -1;
private _linger: number;
private _lingered = 0;
private _standby: Poll.Standby | (() => boolean | Poll.Standby);
private _state: IPoll.State<T, U, V>;
private _tick = new PromiseDelegate<this>();
private _ticked = new Signal<this, IPoll.State<T, U, V>>(this);
Expand Down
3 changes: 2 additions & 1 deletion review/api/polling.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class Poll<T = any, U = any, V extends string = 'standby'> implements IOb
schedule(next?: Partial<IPoll.State<T, U, V> & {
cancel: (last: IPoll.State<T, U, V>) => boolean;
}>): Promise<void>;
standby: Poll.Standby | (() => boolean | Poll.Standby);
get standby(): Poll.Standby | (() => boolean | Poll.Standby);
set standby(standby: Poll.Standby | (() => boolean | Poll.Standby));
start(): Promise<void>;
get state(): IPoll.State<T, U, V>;
stop(): Promise<void>;
Expand Down

0 comments on commit ee26730

Please sign in to comment.