-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
5 changed files
with
115 additions
and
31 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
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,24 @@ | ||
// Copyright 2020-2021 The golang.design Initiative Authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a MIT license that can be found in the LICENSE file. | ||
// | ||
// Written by Changkun Ou <changkun.de> | ||
|
||
package mainthread_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.design/x/mainthread" | ||
) | ||
|
||
func BenchmarkCall(b *testing.B) { | ||
f := func() {} | ||
mainthread.Init(func() { | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
mainthread.Call(f) | ||
} | ||
}) | ||
} |
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,40 @@ | ||
// Copyright 2020-2021 The golang.design Initiative Authors. | ||
// All rights reserved. Use of this source code is governed | ||
// by a MIT license that can be found in the LICENSE file. | ||
// | ||
// Written by Changkun Ou <changkun.de> | ||
|
||
package mainthread_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.design/x/mainthread" | ||
) | ||
|
||
func ExampleInit() { | ||
mainthread.Init(func() { | ||
// ... Do stuff ... | ||
}) | ||
// Output: | ||
} | ||
|
||
func ExampleCall() { | ||
mainthread.Init(func() { | ||
mainthread.Call(func() { | ||
fmt.Println("from main thread") | ||
}) | ||
}) | ||
// Output: from main thread | ||
} | ||
|
||
func ExampleGo() { | ||
mainthread.Init(func() { | ||
done := make(chan string) | ||
mainthread.Go(func() { | ||
done <- "main thread" | ||
}) | ||
fmt.Println("from", <-done) | ||
}) | ||
// Output: from main thread | ||
} |
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