Skip to content

Commit 723a993

Browse files
committed
playground: Make format synchronous.
Previous code would generate "$rootScope:inprog" AngularJS error (see https://docs.angularjs.org/error/$rootScope/inprog). I'm not fully sure what changed to cause that, but it seems this code can now be executed synchronously without a goroutine (i.e., it makes no blocking calls). According to AngularJS documentation (linked above), that is one possible cause of this error: > This error is often seen when interacting with an API that is sometimes sync and sometimes async. Perhaps something changed to cause formatting to no longer by asynchronous. Remove the goroutine and scope.Apply calls. It seems to work, but I'm not familiar with AngularJS enough to be confident this is the best thing to do. I'm also not sure what exactly changed to trigger the original error. Related to #64. Hopefully we can stop relying on AngularJS soon, and this potential problem can go away/wouldn't have happened.
1 parent 5801b5d commit 723a993

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

playground/playground.go

+15-21
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,21 @@ func main() {
206206
}()
207207

208208
scope.Set("format", func() {
209-
go func() {
210-
code := []byte(scope.Get("code").String())
211-
var out []byte
212-
var err error
213-
switch scope.Get("imports").Bool() {
214-
case true:
215-
out, err = imports.Process("prog.go", code, nil)
216-
case false:
217-
out, err = format.Source(code)
218-
}
219-
if err != nil {
220-
scope.Apply(func() {
221-
scope.Set("output", []Line{Line{"type": "err", "content": err.Error()}})
222-
})
223-
return
224-
}
225-
scope.Apply(func() {
226-
scope.Set("code", string(out))
227-
scope.Set("output", []Line{})
228-
})
229-
}()
209+
code := []byte(scope.Get("code").String())
210+
var out []byte
211+
var err error
212+
switch scope.Get("imports").Bool() {
213+
case true:
214+
out, err = imports.Process("prog.go", code, nil)
215+
case false:
216+
out, err = format.Source(code)
217+
}
218+
if err != nil {
219+
scope.Set("output", []Line{Line{"type": "err", "content": err.Error()}})
220+
return
221+
}
222+
scope.Set("code", string(out))
223+
scope.Set("output", []Line{})
230224
})
231225

232226
scope.Set("share", func() {

0 commit comments

Comments
 (0)