What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {
# These are my notes from the PragProg book on CoffeeScript of things that either | |
# aren't in the main CS language reference or I didn't pick them up there. I wrote | |
# them down before I forgot, and put it here for others but mainly as a reference for | |
# myself. | |
# assign arguments in constructor to properties of the same name: | |
class Thingie | |
constructor: (@name, @url) -> | |
# is the same as: |
require 'rubygems' | |
require 'couchbase' | |
def transfer(source, destination, amount) | |
cb = Couchbase.bucket | |
# prepare transaction document | |
id = cb.incr("transaction:counter", :create => true) | |
trans_id = "transaction:#{id}" | |
cb.set(trans_id, {"source" => source, "destination" => destination, |
-- turns a dictionary table into a bulk reply table | |
local dict2bulk = function (dict) | |
local result = {} | |
for k, v in pairs(dict) do | |
table.insert(result, k) | |
table.insert(result, v) | |
end | |
return result | |
end |
-- gets all fields from a hash as a dictionary | |
local hgetall = function (key) | |
local bulk = redis.call('HGETALL', key) | |
local result = {} | |
local nextkey | |
for i, v in ipairs(bulk) do | |
if i % 2 == 1 then | |
nextkey = v | |
else | |
result[nextkey] = v |
-- sets all fields for a hash from a dictionary | |
local hmset = function (key, dict) | |
if next(dict) == nil then return nil end | |
local bulk = {} | |
for k, v in pairs(dict) do | |
table.insert(bulk, k) | |
table.insert(bulk, v) | |
end | |
return redis.call('HMSET', key, unpack(bulk)) | |
end |
var gulp = require('gulp'), | |
debug = require('gulp-debug'), | |
size = require('gulp-filesize'), | |
clean = require('gulp-clean'), | |
coffee = require('gulp-coffee'), | |
coffeelint = require('gulp-coffeelint'), | |
gutil = require('gulp-util'), | |
sass = require('gulp-sass'), | |
imagemin = require('gulp-imagemin'), | |
changed = require('gulp-changed'), |
#!/bin/sh | |
lock() { | |
i3lock | |
} | |
case "$1" in | |
lock) | |
lock | |
;; | |
logout) |
What is sync.Pool in golang and How to use it
sync.Pool (1/2)
Many Go libraries include custom thread-safe free lists, like this:
var objPool = make(chan *Object, 10)
func obj() *Object {
select {
/** | |
* The MIT License (MIT) | |
* | |
* Copyright (c) 2015 Circle Internet Financial | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
/* bling.js */ | |
window.$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function (name, fn) { | |
this.addEventListener(name, fn); | |
} | |
NodeList.prototype.__proto__ = Array.prototype; |