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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ReactWindows/ReactNative.Net46/ReactPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using ReactNative.Modules.Core;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -181,7 +182,7 @@ protected virtual ReactRootView CreateRootView()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAcceleratorKeyActivated(object sender, KeyEventArgs e)
private async void OnAcceleratorKeyActivated(object sender, KeyEventArgs e)
{
if (ReactInstanceManager.DevSupportManager.IsEnabled)
{
Expand All @@ -196,7 +197,7 @@ private void OnAcceleratorKeyActivated(object sender, KeyEventArgs e)
// Ctrl+R
if (isCtrlKeyDown && e.Key == Key.R)
{
ReactInstanceManager.DevSupportManager.HandleReloadJavaScript();
await ReactInstanceManager.DevSupportManager.CreateReactContextFromPackagerAsync(CancellationToken.None);
}
}

Expand Down
16 changes: 9 additions & 7 deletions ReactWindows/ReactNative.Shared/Bridge/JavaScriptBundleLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
#if WINDOWS_UWP
using Windows.Storage;
Expand Down Expand Up @@ -27,8 +28,9 @@ public abstract class JavaScriptBundleLoader
/// Initializes the JavaScript bundle loader, typically making an
/// asynchronous call to cache the bundle in memory.
/// </summary>
/// <param name="token">A token to cancel the initialization.</param>
/// <returns>A task to await initialization.</returns>
public abstract Task InitializeAsync();
public abstract Task InitializeAsync(CancellationToken token);

/// <summary>
/// Loads the bundle into a JavaScript executor.
Expand Down Expand Up @@ -89,13 +91,13 @@ public override string SourceUrl
}

#if WINDOWS_UWP
public override async Task InitializeAsync()
public override async Task InitializeAsync(CancellationToken token)
{
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(SourceUrl)).AsTask().ConfigureAwait(false);
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(SourceUrl)).AsTask(token).ConfigureAwait(false);
_script = storageFile.Path;
}
#else
public override Task InitializeAsync()
public override Task InitializeAsync(CancellationToken token)
{
var assembly = Assembly.GetAssembly(typeof(JavaScriptBundleLoader));
var assemblyName = assembly.GetName();
Expand Down Expand Up @@ -134,11 +136,11 @@ public CachedJavaScriptBundleLoader(string sourceUrl, string cachedFileLocation)

public override string SourceUrl { get; }

public override async Task InitializeAsync()
public override async Task InitializeAsync(CancellationToken token)
{
#if WINDOWS_UWP
var localFolder = ApplicationData.Current.LocalFolder;
var storageFile = await localFolder.GetFileAsync(_cachedFileLocation).AsTask().ConfigureAwait(false);
var storageFile = await localFolder.GetFileAsync(_cachedFileLocation).AsTask(token).ConfigureAwait(false);
#else
var localFolder = FileSystem.Current.LocalStorage;
var storageFile = await localFolder.GetFileAsync(_cachedFileLocation).ConfigureAwait(false);
Expand Down Expand Up @@ -170,7 +172,7 @@ public override string SourceUrl
get;
}

public override Task InitializeAsync()
public override Task InitializeAsync(CancellationToken token)
{
return Task.CompletedTask;
}
Expand Down
5 changes: 3 additions & 2 deletions ReactWindows/ReactNative.Shared/Bridge/ReactInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using static System.FormattableString;

Expand Down Expand Up @@ -81,9 +82,9 @@ public void Initialize()
QueueConfiguration.NativeModulesQueue.Dispatch(_registry.NotifyReactInstanceInitialize);
}

public async Task InitializeBridgeAsync()
public async Task InitializeBridgeAsync(CancellationToken token)
{
await _bundleLoader.InitializeAsync().ConfigureAwait(false);
await _bundleLoader.InitializeAsync(token).ConfigureAwait(false);

using (Tracer.Trace(Tracer.TRACE_TAG_REACT_BRIDGE, "initializeBridge").Start())
{
Expand Down
7 changes: 4 additions & 3 deletions ReactWindows/ReactNative.Shared/DevSupport/DevServerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReactNative.Bridge;
using ReactNative.Bridge;
using System;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -139,13 +139,14 @@ public async Task DownloadBundleFromUrlAsync(string jsModulePath, Stream outputS
/// <summary>
/// Checks if the packager is running.
/// </summary>
/// <param name="token">A token to cancel the request.</param>
/// <returns>A task to await the packager status.</returns>
public async Task<bool> IsPackagerRunningAsync()
public async Task<bool> IsPackagerRunningAsync(CancellationToken token)
{
var statusUrl = CreatePackagerStatusUrl(DebugServerHost);
try
{
using (var response = await _client.GetAsync(statusUrl).ConfigureAwait(false))
using (var response = await _client.GetAsync(statusUrl, token).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
{
Expand Down
Loading