zoukankan      html  css  js  c++  java
  • ruby脚本示例代码

    if __FILE__ == $0
      $:.unshift File.join(File.dirname(__FILE__), '..')
      require 'eventmachine'
      # TODO: real tests
      # TODO: pass in one object instead of two? .each{ |iter| puts iter.current; iter.next }
      # TODO: support iter.pause/resume/stop/break/continue?
      # TODO: create some exceptions instead of using RuntimeError
      # TODO: support proc instead of enumerable? EM::Iterator.new(proc{ return queue.pop })
      EM.run{
        EM::Iterator.new(1..50).each{ |num,iter| p num; iter.next }
        EM::Iterator.new([1,2,3], 10).each{ |num,iter| p num; iter.next }
        i = EM::Iterator.new(1..100, 5)
        i.each(proc{|num,iter|
          p num.to_s
          iter.next
        }, proc{
          p :done
        })
        EM.add_timer(0.03){
          i.concurrency = 1
        }
        EM.add_timer(0.04){
          i.concurrency = 3
        }
        EM::Iterator.new(100..150).map(proc{ |num,iter|
          EM.add_timer(0.01){ iter.return(num) }
        }, proc{ |results|
          p results
        })
        EM::Iterator.new(%w[ pwd uptime uname date ], 2).inject({}, proc{ |hash,cmd,iter|
          EM.system(cmd){ |output,status|
            hash[cmd] = status.exitstatus == 0 ? output.strip : nil
            iter.return(hash)
          }
        }, proc{ |results|
          p results
        })
      }
    end
  • 相关阅读:
    Android ADB 基本命令
    Android Studio修改包名
    Android开发之SurfaceView
    Android呼吸灯效果实现
    Android xml 绘制图形
    设计模式--代理模式C++实现
    设计模式--建造者模式C++实现
    设计模式--模板方法模式C++实现
    设计模式--抽象工厂模式C++实现
    设计模式---工厂方法C++实现
  • 原文地址:https://www.cnblogs.com/lexus/p/1935328.html
Copyright © 2011-2022 走看看