Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
fdba0cb0
Commit
fdba0cb0
authored
Jun 02, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/jsre: ensure Stop can be called more than once
This makes "geth js file.js" terminate again.
parent
16a23ff7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
jsre.go
internal/jsre/jsre.go
+9
-7
No files found.
internal/jsre/jsre.go
View file @
fdba0cb0
...
...
@@ -24,7 +24,6 @@ import (
"io"
"io/ioutil"
"math/rand"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -44,7 +43,7 @@ type JSRE struct {
output
io
.
Writer
evalQueue
chan
*
evalReq
stopEventLoop
chan
bool
loopWg
sync
.
WaitGroup
closed
chan
struct
{}
}
// jsTimer is a single timer instance with a callback function
...
...
@@ -66,10 +65,10 @@ func New(assetPath string, output io.Writer) *JSRE {
re
:=
&
JSRE
{
assetPath
:
assetPath
,
output
:
output
,
closed
:
make
(
chan
struct
{}),
evalQueue
:
make
(
chan
*
evalReq
),
stopEventLoop
:
make
(
chan
bool
),
}
re
.
loopWg
.
Add
(
1
)
go
re
.
runEventLoop
()
re
.
Set
(
"loadScript"
,
re
.
loadScript
)
re
.
Set
(
"inspect"
,
prettyPrintJS
)
...
...
@@ -98,6 +97,8 @@ func randomSource() *rand.Rand {
// functions should be used if and only if running a routine that was already
// called from JS through an RPC call.
func
(
self
*
JSRE
)
runEventLoop
()
{
defer
close
(
self
.
closed
)
vm
:=
otto
.
New
()
r
:=
randomSource
()
vm
.
SetRandomSource
(
r
.
Float64
)
...
...
@@ -213,8 +214,6 @@ loop:
timer
.
timer
.
Stop
()
delete
(
registry
,
timer
)
}
self
.
loopWg
.
Done
()
}
// Do executes the given function on the JS event loop.
...
...
@@ -227,8 +226,11 @@ func (self *JSRE) Do(fn func(*otto.Otto)) {
// stops the event loop before exit, optionally waits for all timers to expire
func
(
self
*
JSRE
)
Stop
(
waitForCallbacks
bool
)
{
self
.
stopEventLoop
<-
waitForCallbacks
self
.
loopWg
.
Wait
()
select
{
case
<-
self
.
closed
:
case
self
.
stopEventLoop
<-
waitForCallbacks
:
<-
self
.
closed
}
}
// Exec(file) loads and runs the contents of a file
...
...
Write
Preview
Markdown
is supported
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