Skip to content
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

Adapter.relax chaining #221

Merged
merged 9 commits into from
Oct 24, 2020
Merged

Conversation

dhilt
Copy link
Owner

@dhilt dhilt commented Oct 20, 2020

For issue #220.

1. Internal "relax" promise chain

The Adapter.relax method becomes chainable: running a random sequence of N "relax" methods will result in a chain of N promises running strictly one after the other.

Imagine we have 2 async processes that are sensitive to the Scroller's internal processes, and both want the Scroller to be relaxed before running the logic:

async runProcessA() {
  await this.datasource.adapter.relax();
  ...
}
async runProcessB() {
  await this.datasource.adapter.relax();
  ...
}

Prior to this PR, there was possible to fall into a race condition between A and B, for example if both methods were called during the same UIScroll Workflow cycle, or even during the same javascript call stack. This PR handles such situation and provides an additional internal queue for any number of logical units (...) that are protected by the "Adapter.relax" promises.

2. Return value of "relax"

As we know, each Adapter method returns a promise of

{
    success: boolean,
    immediate: boolean,
    details?: string
}

This PR makes it true also for the Adapter.relax method, and there is one important case where it might be very useful. Imagine the following sequence running in the same call stack:

runProcessA()
Adapter.reload()
runProcessB()

Reload is not protected by "relax", we just want to interrupt the Scroller and stop all its activities. Scroller can't cancel the code following after the Adapter.relax promise, but it can tell that the flow was interrupted, it uses "success" field:

async runProcessB() {
  const { success } = await this.datasource.adapter.relax();
  if (!success) {
    return; // we don't want to proceed if the Scroller has been reloaded
  }
  ...
}

So, if the App can reload the Scroller, I would suggest to use the Adapter-relax-success protection.

@dhilt dhilt marked this pull request as ready for review October 24, 2020 18:06
@dhilt dhilt merged commit 2bb0064 into master Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant