channelにbufferがあるかないかで、channelを使った同期の挙動が異なる。
詳しくは、公式のThe Go Memory Modelを参照。
以下のルールに従う。 bufferの有無で、送信と受信の優先順位が変わるので注意。
| var http = require('http'); | |
| server = http.createServer(function (req, res) { | |
| res.writeHead(200, {'Content-Type': 'text/plain'}); | |
| res.end('Hello World\n'); | |
| server.close(); | |
| }); | |
| server.listen(8080, 0, function () { | |
| console.log('Server running at http://localhost:8080/'); | |
| }); |
| from PIL import Image, ImageDraw | |
| my_data = [line.split('\t') for line in file('decision_tree_example.txt')] | |
| class decisionnode: | |
| def __init__(self, col = -1, value = None, results = None, tb = None, fb = None): | |
| self.col = col | |
| self.value = value | |
| self.results = results | |
| self.tb = tb | |
| self.fb = fb |
| plus :: Int -> Int -> Int | |
| plus m 0 = m | |
| plus m n | |
| | n > 0 = plus m (n - 1) + 1 | |
| | n < 0 = plus m (n + 1) - 1 | |
| minus :: Int -> Int -> Int | |
| minus m 0 = m | |
| minus m n | |
| | n > 0 = minus m (n - 1) - 1 |
| package main | |
| import "fmt" | |
| type EvalFunc func(interface{}) (interface{}, interface{}) | |
| func BuildLazyEvaluator(evalFunc EvalFunc, initState interface{}) func() interface{} { | |
| retValChan := make(chan interface{}) | |
| loopFunc := func() { |
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| ) | |
| func main() { | |
| ch := make(chan int) | |
| var wg sync.WaitGroup |
| package closure | |
| type Request struct { | |
| Url string | |
| } | |
| func Closure1(reqs []*Request) { | |
| for _, req := range reqs { | |
| go func(req *Request) { | |
| req.Url = "http://example.org" |
channelにbufferがあるかないかで、channelを使った同期の挙動が異なる。
詳しくは、公式のThe Go Memory Modelを参照。
以下のルールに従う。 bufferの有無で、送信と受信の優先順位が変わるので注意。
| acpi | grep -oE \[0-9\]+% |
| var http = require('http'); | |
| http.createServer(function(req, res) { | |
| if(req.method === 'POST') { | |
| res.end('POST'); | |
| console.log('POST'); | |
| } else if (req.method === 'GET') { | |
| res.end('GET'); | |
| console.log('GET'); | |
| } else { |