Skip to content

Instantly share code, notes, and snippets.

View pathbox's full-sized avatar
💪
Don't stop moving on!

Cary pathbox

💪
Don't stop moving on!
View GitHub Profile
@pathbox
pathbox / em-fiber.rb
Last active March 3, 2016 08:47
em-fiber(转)
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 有关 Fiber 的解释: (按照数据流的方向分为两部分)
# 在 `主线程' 中使用 resume 方法来启动(或继续执行)一个 `纤程'.
# 1. 第一次调用 fiber.resume, 会启动一个纤程,
# 如果 resume 调用时提供了实参, 会作为代码块形参传入代码块.
# 2. 如果非第一次调用 fiber.resume, 即, `恢复' 一个纤程, 会做两件事:
# - 从上次离开纤程的那个位置(调用 Fiber.yield 离开纤程的那个位置), 恢复纤程的执行.