New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use new Poll class for filebrowser contents polling. #6305
Changes from 1 commit
8a93826
07d7b4d
e3ee844
627b1db
99faafa
be4cc1a
6746f7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -35,11 +35,6 @@ import { showDialog, Dialog } from '@jupyterlab/apputils'; | |||||||||
*/ | ||||||||||
const DEFAULT_REFRESH_INTERVAL = 10000; | ||||||||||
|
||||||||||
/** | ||||||||||
* The enforced time between refreshes in ms. | ||||||||||
*/ | ||||||||||
const MIN_REFRESH = 1000; | ||||||||||
|
||||||||||
/** | ||||||||||
* The maximum upload size (in bytes) for notebook version < 5.1.0 | ||||||||||
*/ | ||||||||||
|
@@ -104,13 +99,7 @@ export class FileBrowserModel implements IDisposable { | |||||||||
}; | ||||||||||
window.addEventListener('beforeunload', this._unloadEventListener); | ||||||||||
this._poll = new Poll({ | ||||||||||
factory: async () => { | ||||||||||
const date = new Date().getTime(); | ||||||||||
if (date - this._lastRefresh < MIN_REFRESH) { | ||||||||||
return; | ||||||||||
} | ||||||||||
return this.refresh(); | ||||||||||
}, | ||||||||||
factory: () => this.cd('.'), | ||||||||||
frequency: { | ||||||||||
interval: refreshInterval, | ||||||||||
backoff: true, | ||||||||||
|
@@ -239,8 +228,7 @@ export class FileBrowserModel implements IDisposable { | |||||||||
* Force a refresh of the directory contents. | ||||||||||
*/ | ||||||||||
refresh(): Promise<void> { | ||||||||||
this._lastRefresh = new Date().getTime(); | ||||||||||
return this.cd('.'); | ||||||||||
return this._poll.refresh(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to refresh, then return the poll's tick promise. The refresh just schedules the refresh, the actual action happens at the end of the tick. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just make an async function like the tests: await this._poll.refresh();
await this._poll.tick; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks, I had misunderstood the function signature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed making the refresh return the tick promise, but then it would be inconsistent with the other scheduling functions like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should at least make a note in the refresh method about this subtlety. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like We can get around this by not calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Roughly, the order I think should be (IIRC):
At this point the await poll.refresh should return, and you await the poll.tick promise. The animation frame triggers, which awaits the poll action, then poll.schedules a 'resolved' state for the normal poll interval, and as part of the poll schedule, it resolves the poll.tick promise you were awaiting. The poll.tick promise is resolved with the poll instance, so you can check the poll state (which should be the 'resolved' state that was scheduled). Does that help? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was happening as expected.
Also happening as expected.
I don't think this is occurring as described, in particular, the resolution of the current tick does not seem to wait on the factory function: jupyterlab/packages/coreutils/src/poll.ts Lines 400 to 403 in 8c72b12
Agreed.
Agreed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The poll action happens in the execute, and after the factory is run and the result resolves, then schedule is called to schedule a resolve state. That's why the tick happens after the factory runs. |
||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
|
@@ -625,7 +613,6 @@ export class FileBrowserModel implements IDisposable { | |||||||||
private _pending: Promise<void> | null = null; | ||||||||||
private _pendingPath: string | null = null; | ||||||||||
private _refreshed = new Signal<this, void>(this); | ||||||||||
private _lastRefresh = -1; | ||||||||||
private _sessions: Session.IModel[] = []; | ||||||||||
private _state: IStateDB | null = null; | ||||||||||
private _driveName: string; | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is really that this factory function should be async. It's not waiting for the cd to finish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that was an incorrect comment. It is returning a promise, so that should be good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is async, since
this.cd('.')
returns a promise. In some of my testing it was explicitly marked asasync
, which made no difference.