This file contains hidden or 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
package repository_test | |
import ( | |
"context" | |
"testing" | |
"time" | |
"github.com/stretchr/testify/assert" | |
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1" |
This file contains hidden or 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
// 高阶函数 | |
func multiply(a int) func(int) int { | |
return func(i int) int { | |
return a * i | |
} | |
} | |
func subtract(a int) func(int) int { | |
return func(i int) int { | |
return i - a | |
} |
This file contains hidden or 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
var ( | |
wg sync.WaitGroup | |
seriesSetChan = make(chan genericSeriesSet) | |
) | |
// Schedule all Selects for all queriers we know about. | |
for _, querier := range q.queriers { | |
wg.Add(1) | |
go func(qr genericQuerier) { | |
defer wg.Done() |
This file contains hidden or 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
// multiError type allows combining multiple errors into one. | |
type multiError []error | |
// NewMulti returns multiError with provided errors added if not nil. | |
func NewMulti(errs ...error) multiError { // nolint:revive | |
m := multiError{} | |
// 多个error的定义 | |
m.Add(errs...) | |
return m | |
} |
This file contains hidden or 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
// CopyDirs copies all directories, subdirectories and files recursively including the empty folders. | |
// Source and destination must be full paths. | |
func CopyDirs(src, dest string) error { | |
if err := os.MkdirAll(dest, 0o777); err != nil { | |
return err | |
} | |
// 获取所有的文件 | |
files, err := readDirs(src) | |
if err != nil { | |
return err |
This file contains hidden or 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
// go build -gcflags="-m"` | |
// 可以进行逃逸分析 | |
package main | |
func main() { | |
var m = make([]int, 10240) | |
println(m[0]) | |
} |
This file contains hidden or 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
-- https://github.com/TimUntersberger/neogit/blob/master/lua/neogit/lib/buffer.lua) | |
package.loaded['neogit.buffer'] = nil | |
__BUFFER_AUTOCMD_STORE = {} | |
local mappings_manager = require("neogit.lib.mappings_manager") | |
local Ui = require("neogit.lib.ui") | |
local Buffer = { | |
handle = nil, |
This file contains hidden or 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
var catalogData = { | |
"booksByIsbn": { | |
"978-1779501127": { | |
"isbn": "978-1779501127", | |
"title": "Watchmen", | |
"publicationYear": 1987, | |
"authorIds": ["alan-moore", "dave-gibbons"], | |
"bookItems": [{ | |
"id": "book-item-1", | |
"libId": "nyc-central-lib", |
This file contains hidden or 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
/// https://rust-lang.github.io/async-book/04_pinning/01_chapter.html | |
/// https://rust-lang.github.io/async-book/04_pinning/01_chapter.html | |
/// Task executor that receives tasks off of a channel and runs them. | |
struct Executor { | |
ready_queue: Receiver<Arc<Task>>, | |
} | |
/// `Spawner` spawns new futures onto the task channel. | |
#[derive(Clone)] | |
struct Spawner { |
This file contains hidden or 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
impl Executor { | |
fn run(&self) { | |
while let Ok(task) = self.ready_queue.recv() { | |
// Take the future, and if it has not yet completed (is still Some), | |
// poll it in an attempt to complete it. | |
let mut future_slot = task.future.lock().unwrap(); | |
if let Some(mut future) = future_slot.take() { | |
// Create a `LocalWaker` from the task itself | |
let waker = waker_ref(&task); | |
let context = &mut Context::from_waker(&*waker); |