-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d79b421
commit 9e00b9d
Showing
9 changed files
with
135 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
distribution/lib/Standard/Base/0.0.0-dev/src/Network/Reload_Detector.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Standard.Base.Error.Error | ||
import Standard.Base.Meta | ||
import Standard.Base.Nothing.Nothing | ||
import Standard.Base.Runtime.Managed_Resource.Managed_Resource | ||
import Standard.Base.Runtime.Ref.Ref | ||
from Standard.Base.Data.Boolean import Boolean, True, False | ||
|
||
## PRIVATE | ||
This is used by ReloadDetector.java to create a `Managed_Resource` that is | ||
garbage collected when the reload button is pressed. | ||
|
||
The managed resource contains a Ref containing a 0 (the value is | ||
unimportant). When the reload button is pressed, the ref is removed and | ||
attempting to access it using `with` throws an `Uninitialized_State`. When | ||
the `Uninitialized_State` is detected, it indicates that the reload has been | ||
initiated. | ||
type Reload_Detector | ||
private Value mr:Managed_Resource | ||
|
||
new -> Reload_Detector = | ||
mr = Managed_Resource.register (Ref.new 1) (x-> Nothing) True | ||
Reload_Detector.Value mr | ||
|
||
has_reload_occurred self = | ||
self.mr.has_been_finalized | ||
|
||
## PRIVATE | ||
simulate_reload_test_only reload_detector = reload_detector.mr.finalize | ||
|
||
## PRIVATE | ||
create_reload_detector = Reload_Detector.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
std-bits/base/src/main/java/org/enso/base/cache/ReloadDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.enso.base.cache; | ||
|
||
import org.enso.base.polyglot.EnsoMeta; | ||
import org.graalvm.polyglot.Value; | ||
|
||
/** | ||
* Detects that the reload button has been pressed. | ||
* | ||
* <p>.hasReloadOccurred() returns true if the reload button was pressed since the last call to | ||
* .hasReloadOccurred(). | ||
* | ||
* <p>This uses a `Managed_Resource` (created in eval'd Enso code) that is cleared on reload. | ||
*/ | ||
public class ReloadDetector { | ||
private Value ensoReloadDetector; | ||
|
||
public ReloadDetector() { | ||
resetEnsoReloadDetector(); | ||
} | ||
|
||
public boolean hasReloadOccurred() { | ||
var reloadHasOccurred = ensoReloadDetector.invokeMember("has_reload_occurred").asBoolean(); | ||
if (reloadHasOccurred) { | ||
resetEnsoReloadDetector(); | ||
} | ||
return reloadHasOccurred; | ||
} | ||
|
||
private void resetEnsoReloadDetector() { | ||
ensoReloadDetector = | ||
EnsoMeta.callStaticModuleMethod( | ||
"Standard.Base.Network.Reload_Detector", "create_reload_detector"); | ||
} | ||
|
||
void simulateReloadTestOnly() { | ||
EnsoMeta.callStaticModuleMethod( | ||
"Standard.Base.Network.Reload_Detector", "simulate_reload_test_only", ensoReloadDetector); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters