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

refactor(ReactInstanceManager): Support awaitable ReactContext #1458

Merged
merged 1 commit into from
Oct 31, 2017

Conversation

rozele
Copy link
Collaborator

@rozele rozele commented Oct 18, 2017

Currently, the ReactInstanceManager kicks off the process to create the ReactContext in the background and its not awaitable. This ensures a single asynchronous thread is available from start to finish for ReactContext creation.

Fixes #1448

@codecov-io
Copy link

codecov-io commented Oct 18, 2017

Codecov Report

Merging #1458 into master will decrease coverage by 0.07%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1458      +/-   ##
==========================================
- Coverage   31.54%   31.47%   -0.08%     
==========================================
  Files         266      266              
  Lines       19253    19296      +43     
  Branches     1599     1613      +14     
==========================================
  Hits         6073     6073              
- Misses      13030    13072      +42     
- Partials      150      151       +1
Impacted Files Coverage Δ
...eactNative.Shared/Bridge/JavaScriptBundleLoader.cs 0% <ø> (ø) ⬆️
...ive.Shared/DevSupport/DisabledDevSupportManager.cs 0% <0%> (ø) ⬆️
ReactWindows/ReactNative.Net46/ReactPage.cs 0% <0%> (ø) ⬆️
...s/ReactNative.Shared/DevSupport/DevServerHelper.cs 0% <0%> (ø) ⬆️
ReactWindows/ReactNative.Shared/ReactRootView.cs 0% <0%> (ø) ⬆️
...actNative.Shared/ReactInstanceManagerExtensions.cs 0% <0%> (ø)
...ReactNative.Shared/DevSupport/DevSupportManager.cs 0% <0%> (ø) ⬆️
...Windows/ReactNative.Shared/Bridge/ReactInstance.cs 0% <0%> (ø) ⬆️
...Windows/ReactNative.Shared/ReactInstanceManager.cs 0% <0%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4a357d...212bfd4. Read the comment docs.

@@ -0,0 +1,32 @@
using ReactNative.Bridge;
using ReactNative.DevSupport;
using System;
Copy link
Collaborator Author

@rozele rozele Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete unused usings. #Closed

@@ -110,7 +111,7 @@ public void StartReactApplication(ReactInstanceManager reactInstanceManager, str

if (!_reactInstanceManager.HasStartedCreatingInitialContext)
{
_reactInstanceManager.CreateReactContextInBackground();
_reactInstanceManager.CreateReactContextAsync(CancellationToken.None);
Copy link
Collaborator Author

@rozele rozele Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateReactContextAsync [](start = 38, length = 23)

Likely has a warning, will need to await the task. #Closed

{
var moved = false;
#if WINDOWS_UWP
var temporaryFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(JSBundleFileName, CreationCollisionOption.GenerateUniqueName);
var temporaryFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(JSBundleFileName, CreationCollisionOption.GenerateUniqueName).AsTask(token);
try
{
using (var stream = await temporaryFile.OpenStreamForWriteAsync())
{
await _devServerHelper.DownloadBundleFromUrlAsync(_jsAppBundleName, stream, token);
Copy link
Collaborator Author

@rozele rozele Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DownloadBundleFromUrlAsync [](start = 43, length = 26)

Add ConfigureAwaits #Closed

await temporaryFile.MoveAsync(
ApplicationData.Current.LocalFolder,
JSBundleFileName,
NameCollisionOption.ReplaceExisting).AsTask();
Copy link
Collaborator Author

@rozele rozele Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsTask [](start = 57, length = 6)

Add comment about why CancellationToken not used here. #Closed


return await _reactInstanceCommandsHandler.CreateReactContextWithRemoteDebuggerAsync(factory, token);
}
finally
Copy link
Collaborator Author

@rozele rozele Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally [](start = 12, length = 7)

May need to catch some exceptions here... #Closed

@@ -110,7 +111,7 @@ public void StartReactApplication(ReactInstanceManager reactInstanceManager, str

if (!_reactInstanceManager.HasStartedCreatingInitialContext)
{
_reactInstanceManager.CreateReactContextInBackground();
_reactInstanceManager.CreateReactContextAsync(CancellationToken.None);
}
Copy link
Collaborator Author

@rozele rozele Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetOrCreate #Closed

Currently, the ReactInstanceManager kicks off the process to create the ReactContext in the background and its not awaitable. This ensures a single asynchronous thread is available from start to finish for ReactContext creation.

Fixes microsoft#1448
@rozele rozele merged commit 4858d42 into microsoft:master Oct 31, 2017
@rozele rozele deleted the issue1448 branch October 31, 2017 17:55
rozele added a commit that referenced this pull request Oct 31, 2017
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.

2 participants