Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
3f74cd1c
Commit
3f74cd1c
authored
7 years ago
by
Aleksey Pivovarov
Browse files
Options
Download
Email Patches
Plain Diff
BackgroundTaskUtil: cleanup - inline method
parent
699a49aa
Branches unavailable
Tags unavailable
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java
+44
-53
...om/intellij/openapi/progress/util/BackgroundTaskUtil.java
with
44 additions
and
53 deletions
+44
-53
platform/platform-impl/src/com/intellij/openapi/progress/util/BackgroundTaskUtil.java
+
44
-
53
View file @
3f74cd1c
...
...
@@ -205,67 +205,63 @@ public class BackgroundTaskUtil {
@NotNull
@CalledInAny
public
static
ProgressIndicator
executeOnPooledThread
(
@NotNull
Disposable
parent
,
@NotNull
Runnable
runnable
)
{
ModalityState
modalityState
=
ModalityState
.
defaultModalityState
();
return
runUnderDisposeAwareIndicator
(
runnable
,
parent
,
modalityState
,
true
);
}
@CalledInAny
private
static
ProgressIndicator
runUnderDisposeAwareIndicator
(
@NotNull
Runnable
task
,
@NotNull
Disposable
parent
,
@NotNull
ModalityState
modalityState
,
boolean
onPooledThread
)
{
ProgressIndicator
indicator
=
new
EmptyProgressIndicator
(
modalityState
);
ProgressIndicator
indicator
=
new
EmptyProgressIndicator
();
indicator
.
start
();
if
(
onPooledThread
)
{
CompletableFuture
<?>
future
=
CompletableFuture
.
runAsync
(()
->
{
ProgressManager
.
getInstance
().
runProcess
(
task
,
indicator
);
},
AppExecutorUtil
.
getAppExecutorService
());
CompletableFuture
<?>
future
=
CompletableFuture
.
runAsync
(()
->
{
ProgressManager
.
getInstance
().
runProcess
(
runnable
,
indicator
);
},
AppExecutorUtil
.
getAppExecutorService
());
Disposable
disposable
=
()
->
{
if
(
indicator
.
isRunning
())
indicator
.
cancel
();
try
{
future
.
get
(
1
,
TimeUnit
.
SECONDS
);
}
catch
(
ExecutionException
e
)
{
if
(
e
.
getCause
()
instanceof
ProcessCanceledException
)
{
// ignore: expected cancellation
}
else
{
LOG
.
error
(
e
);
}
Disposable
disposable
=
()
->
{
if
(
indicator
.
isRunning
())
indicator
.
cancel
();
try
{
future
.
get
(
1
,
TimeUnit
.
SECONDS
);
}
catch
(
ExecutionException
e
)
{
if
(
e
.
getCause
()
instanceof
ProcessCanceledException
)
{
// ignore: expected cancellation
}
catch
(
InterruptedException
|
TimeoutException
e
)
{
else
{
LOG
.
error
(
e
);
}
};
if
(!
registerIfParentNotDisposed
(
parent
,
disposable
))
{
indicator
.
cancel
();
return
indicator
;
}
future
.
whenComplete
((
o
,
e
)
->
Disposer
.
dispose
(
disposable
));
}
else
{
Disposable
disposable
=
()
->
{
if
(
indicator
.
isRunning
())
indicator
.
cancel
();
};
if
(!
registerIfParentNotDisposed
(
parent
,
disposable
))
{
indicator
.
cancel
();
return
indicator
;
catch
(
InterruptedException
|
TimeoutException
e
)
{
LOG
.
error
(
e
);
}
};
try
{
ProgressManager
.
getInstance
().
runProcess
(
task
,
indicator
);
}
finally
{
Disposer
.
dispose
(
disposable
);
}
if
(!
registerIfParentNotDisposed
(
parent
,
disposable
))
{
indicator
.
cancel
();
return
indicator
;
}
future
.
whenComplete
((
o
,
e
)
->
Disposer
.
dispose
(
disposable
));
return
indicator
;
}
@CalledInAny
public
static
void
runUnderDisposeAwareIndicator
(
@NotNull
Disposable
parent
,
@NotNull
Runnable
task
)
{
ProgressIndicator
indicator
=
new
EmptyProgressIndicator
(
ModalityState
.
defaultModalityState
());
indicator
.
start
();
Disposable
disposable
=
()
->
{
if
(
indicator
.
isRunning
())
indicator
.
cancel
();
};
if
(!
registerIfParentNotDisposed
(
parent
,
disposable
))
{
indicator
.
cancel
();
return
;
}
try
{
ProgressManager
.
getInstance
().
runProcess
(
task
,
indicator
);
}
finally
{
Disposer
.
dispose
(
disposable
);
}
}
private
static
boolean
registerIfParentNotDisposed
(
@NotNull
Disposable
parent
,
@NotNull
Disposable
disposable
)
{
return
ReadAction
.
compute
(()
->
{
if
(
Disposer
.
isDisposed
(
parent
))
return
false
;
...
...
@@ -280,11 +276,6 @@ public class BackgroundTaskUtil {
});
}
@CalledInAny
public
static
void
runUnderDisposeAwareIndicator
(
@NotNull
Disposable
parent
,
@NotNull
Runnable
task
)
{
runUnderDisposeAwareIndicator
(
task
,
parent
,
ModalityState
.
defaultModalityState
(),
false
);
}
/**
* Wraps {@link MessageBus#syncPublisher(Topic)} in a dispose check,
* and throws a {@link ProcessCanceledException} if the project is disposed,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help