Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LightIO is a userland implemented green thread library for ruby

License

NotificationsYou must be signed in to change notification settings

socketry/lightio

Repository files navigation

Gem VersionBuild StatusCoverage StatusMIT licensedGitter

LightIO provides green thread to ruby. Like Golang's goroutine, or Crystal's fiber. In LightIO it is called beam.

Example:

require'lightio'start=Time.nowbeams=1000.times.mapdo# LightIO::Beam is green-thread, use it instead ThreadLightIO::Beam.newdo# do some io operations in beamLightIO.sleep(1)endendbeams.each(&:join)seconds=Time.now -startputs"1000 beams take#{seconds -1} seconds to create"

LightIO ship ruby stdlib compatible library underLightIO orLightIO::Library namespace,these libraries provide the ability to schedule LightIO beams when IO operations occur.

LightIO also provide a monkey patch, it replaces rubyThread withLightIO::Thread, and also replacesIO related classes.

Example:

require'lightio'# apply monkey patch at beginningLightIO::Monkey.patch_all!require'net/http'host='github.com'port=443start=Time.now10.times.mapdoThread.newdoNet::HTTP.start(host,port,use_ssl:true)do |http|res=http.request_get('/ping')pres.codeendendend.each(&:join)puts"#{Time.now -start} seconds"

SeeExamples for detail.

You Should Know

In fact ruby core team already plan to implementThread::Green in core language, seehttps://bugs.ruby-lang.org/issues/13618

It means if ruby implementedThread::Green, this library has no reason to exist.But as a crazy userland implemented green thread library, it bring lots of fun to me, so I will continue to maintain it, and welcome to use.

SeeWiki andRoadmap to get more information.

LightIO is build uponnio4r. Get heavily inspired bygevent,async-io.

Installation

Add this line to your application's Gemfile:

gem'lightio'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lightio

Documentation

Please see LightIO Wiki for more information.

The following documentations is also usable:

Discussion

https://groups.google.com/group/lightio

Development

After checking out the repo, runbin/setup to install dependencies. Then, runrake spec to run the tests. You can also runbin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, runbundle exec rake install. To release a new version, update the version number inversion.rb, and then runbundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the.gem file torubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub athttps://github.com/jjyr/lightio. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to theContributor Covenant code of conduct.

License

The gem is available as open source under the terms of theMIT License.

Copyright, 2017-2018, byJiang Jinyang

Code of Conduct

Everyone interacting in the Lightio project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow thecode of conduct.

About

LightIO is a userland implemented green thread library for ruby

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp