Skip to content

Commit

Permalink
example: initialize loaded module in a new thread
Browse files Browse the repository at this point in the history
Change-Id: Id44cc1dc3f6112764080b2dcef358dfd25fbdbcd
  • Loading branch information
adonovan committed Oct 10, 2017
1 parent ae06384 commit 6c3fcb8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func ExampleLoadSequential() {

cache := make(map[string]*entry)

load := func(thread *skylark.Thread, module string) (skylark.StringDict, error) {
var load func(_ *skylark.Thread, module string) (skylark.StringDict, error)
load = func(_ *skylark.Thread, module string) (skylark.StringDict, error) {
e, ok := cache[module]
if e == nil {
if ok {
Expand All @@ -85,8 +86,9 @@ func ExampleLoadSequential() {
// Add a placeholder to indicate "load in progress".
cache[module] = nil

// Load it.
// Load and initialize the module in a new thread.
data := fakeFilesystem[module]
thread := &skylark.Thread{Load: load}
globals := make(skylark.StringDict)
err := skylark.ExecFile(thread, module, data, globals)
e = &entry{globals, err}
Expand Down

0 comments on commit 6c3fcb8

Please sign in to comment.