Skip to content

Commit

Permalink
Make executor an instance property (flutter#3633)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored Feb 25, 2021
1 parent f614980 commit cb64042
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ build/
.project
.classpath
.settings

# Downloaded by the plugin tools.
google-java-format-1.3-all-deps.jar
4 changes: 4 additions & 0 deletions packages/shared_preferences/shared_preferences/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.2

* Don't create additional thread pools when method channel is called.

## 2.0.1

* Removed deprecated [AsyncTask](https://developer.android.com/reference/android/os/AsyncTask) was deprecated in API level 30 ([#3481](https://github.com/flutter/plugins/pull/3481))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {

private final android.content.SharedPreferences preferences;

private final ExecutorService executor;

/**
* Constructs a {@link MethodCallHandlerImpl} instance. Creates a {@link
* android.content.SharedPreferences} based on the {@code context}.
*/
MethodCallHandlerImpl(Context context) {
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
executor =
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
}

@Override
Expand Down Expand Up @@ -123,8 +127,6 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {

private void commitAsync(
final SharedPreferences.Editor editor, final MethodChannel.Result result) {
final ExecutorService executor =
new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
final Handler handler = new Handler(Looper.getMainLooper());

executor.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: shared_preferences
description: Flutter plugin for reading and writing simple key-value pairs.
Wraps NSUserDefaults on iOS and SharedPreferences on Android.
homepage: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences
version: 2.0.1
version: 2.0.2

flutter:
plugin:
Expand Down

0 comments on commit cb64042

Please sign in to comment.