Skip to content

Instantly share code, notes, and snippets.

View cablehead's full-sized avatar

Andy Gayton cablehead

View GitHub Profile
local d = require("levee").d
local ring = d.HashRing()
ring:put("foo", 3, 2)
print(ring:get("foo"))
ring:del("foo")
ring:put("foo", 3, 2)
print(ring:get("foo") == nil)
local levee = require("levee")
local _ = levee._
local h = levee.Hub()
local err, serve = h.tcp:listen(9000)
for conn in serve do
h:spawn(function()
while true do
local levee = require("levee")
local h = levee.Hub()
local connections = 0
-- HTTP endpoint to see number of connections
levee build -e '
local levee = require("levee")
h = levee.Hub()
local err, serve = h.tcp:listen(8080)
for conn in serve do
local msg = "Hello World"
conn:write("HTTP/1.1 200 OK\n")
import time
import functools
from decorator import decorator
import pytest
from tornado import ioloop
from tornado import gen
import time
import functools
from decorator import decorator
import pytest
from tornado import ioloop
from tornado import gen
d.Buffer()
d.Fifo() -- ??
d.FIFO()
d.Heap()
d.Set()
@cablehead
cablehead / 1.md
Last active October 16, 2015 19:09
Abandoned coroutines in Vanilla

Ben Bangert raised an excellent point about leaking abandoned coroutines in a recent talk:

https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/edit#slide=id.g70b0035b2_1_168

This gist demonstrates a design decision in Vanilla to attempt to help with this.

The sender, recver ends of pipes are only connected by weakref's which have callback's registered for when the corresponding end is garbage collected. When one end is blocked on a send or a recv, and the other end is abandoned without being closed explicitly the blocked coroutine will receive a vanilla.Abandoned exception. This will also result in a StopIteration exception if you are iterating over a recver.

@cablehead
cablehead / e.sh
Last active August 26, 2015 07:03
$ levee run -e '
local levee = require("levee")
local h = levee.Hub()
local serve = h.http:listen(8000)
for conn in serve do
h:spawn(function()
local req = conn:recv()
local sys = require("levee.sys")
local r, w = sys.os.pipe()
sys.os.write(w, s, #s)
local r, w = sys.fd.pipe()
sys.fd.write(w, s, #s)