good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
fdba0cb0
Commit
fdba0cb0
authored
Jun 2, 2016
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
internal/jsre: ensure Stop can be called more than once
This makes "geth js file.js" terminate again.
parent
16a23ff7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
internal/jsre/jsre.go
+9
-7
9 additions, 7 deletions
internal/jsre/jsre.go
with
9 additions
and
7 deletions
internal/jsre/jsre.go
+
9
−
7
View file @
fdba0cb0
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"sync"
"time"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -44,7 +43,7 @@ type JSRE struct {
...
@@ -44,7 +43,7 @@ type JSRE struct {
output
io
.
Writer
output
io
.
Writer
evalQueue
chan
*
evalReq
evalQueue
chan
*
evalReq
stopEventLoop
chan
bool
stopEventLoop
chan
bool
lo
opWg
sync
.
WaitGroup
c
lo
sed
chan
struct
{}
}
}
// jsTimer is a single timer instance with a callback function
// jsTimer is a single timer instance with a callback function
...
@@ -66,10 +65,10 @@ func New(assetPath string, output io.Writer) *JSRE {
...
@@ -66,10 +65,10 @@ func New(assetPath string, output io.Writer) *JSRE {
re
:=
&
JSRE
{
re
:=
&
JSRE
{
assetPath
:
assetPath
,
assetPath
:
assetPath
,
output
:
output
,
output
:
output
,
closed
:
make
(
chan
struct
{}),
evalQueue
:
make
(
chan
*
evalReq
),
evalQueue
:
make
(
chan
*
evalReq
),
stopEventLoop
:
make
(
chan
bool
),
stopEventLoop
:
make
(
chan
bool
),
}
}
re
.
loopWg
.
Add
(
1
)
go
re
.
runEventLoop
()
go
re
.
runEventLoop
()
re
.
Set
(
"loadScript"
,
re
.
loadScript
)
re
.
Set
(
"loadScript"
,
re
.
loadScript
)
re
.
Set
(
"inspect"
,
prettyPrintJS
)
re
.
Set
(
"inspect"
,
prettyPrintJS
)
...
@@ -98,6 +97,8 @@ func randomSource() *rand.Rand {
...
@@ -98,6 +97,8 @@ func randomSource() *rand.Rand {
// functions should be used if and only if running a routine that was already
// functions should be used if and only if running a routine that was already
// called from JS through an RPC call.
// called from JS through an RPC call.
func
(
self
*
JSRE
)
runEventLoop
()
{
func
(
self
*
JSRE
)
runEventLoop
()
{
defer
close
(
self
.
closed
)
vm
:=
otto
.
New
()
vm
:=
otto
.
New
()
r
:=
randomSource
()
r
:=
randomSource
()
vm
.
SetRandomSource
(
r
.
Float64
)
vm
.
SetRandomSource
(
r
.
Float64
)
...
@@ -213,8 +214,6 @@ loop:
...
@@ -213,8 +214,6 @@ loop:
timer
.
timer
.
Stop
()
timer
.
timer
.
Stop
()
delete
(
registry
,
timer
)
delete
(
registry
,
timer
)
}
}
self
.
loopWg
.
Done
()
}
}
// Do executes the given function on the JS event loop.
// Do executes the given function on the JS event loop.
...
@@ -227,8 +226,11 @@ func (self *JSRE) Do(fn func(*otto.Otto)) {
...
@@ -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
// stops the event loop before exit, optionally waits for all timers to expire
func
(
self
*
JSRE
)
Stop
(
waitForCallbacks
bool
)
{
func
(
self
*
JSRE
)
Stop
(
waitForCallbacks
bool
)
{
self
.
stopEventLoop
<-
waitForCallbacks
select
{
self
.
loopWg
.
Wait
()
case
<-
self
.
closed
:
case
self
.
stopEventLoop
<-
waitForCallbacks
:
<-
self
.
closed
}
}
}
// Exec(file) loads and runs the contents of a file
// Exec(file) loads and runs the contents of a file
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment