Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d57aa52
commit eb229bd
Showing
22 changed files
with
867 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
################# | ||
## Ruby | ||
################# | ||
|
||
pkg/ | ||
|
||
################# | ||
## Eclipse | ||
################# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in Rx.rb.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
Rx.rb (0.0.1) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.1.3) | ||
rake (10.0.3) | ||
rspec (2.12.0) | ||
rspec-core (~> 2.12.0) | ||
rspec-expectations (~> 2.12.0) | ||
rspec-mocks (~> 2.12.0) | ||
rspec-core (2.12.2) | ||
rspec-expectations (2.12.1) | ||
diff-lcs (~> 1.1.3) | ||
rspec-mocks (2.12.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
Rx.rb! | ||
rake | ||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Microsoft Corporation"] | ||
gem.description = %q{Reactive Extensions for Ruby} | ||
gem.summary = %q{This is an implementation of the Reactive Extensions for Ruby. Note that this is an early prototype, but contributions are welcome.} | ||
gem.homepage = "https://github.com/Reactive-Extensions/Rx.rb" | ||
|
||
gem.files = `git ls-files`.split($\) | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.name = "Rx.rb" | ||
gem.require_paths = ["lib"] | ||
gem.version = "0.0.1" | ||
|
||
gem.add_development_dependency 'rake' | ||
gem.add_development_dependency 'rspec' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class AbstractObserver | ||
def initialize | ||
@stopped = false | ||
end | ||
|
||
def on_completed | ||
unless @stopped | ||
@stopped = true | ||
self.completed | ||
end | ||
end | ||
|
||
def on_error(exception) | ||
# TODO: Error checking | ||
|
||
unless @stopped | ||
@stopped = true | ||
self.error(exception) | ||
end | ||
end | ||
|
||
def on_next(value) | ||
unless @stopped | ||
self.next(value) | ||
end | ||
end | ||
|
||
def stop | ||
@stopped = true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class AutoDetachDisposable | ||
def initialize(observer) | ||
@gate = Mutex.new | ||
@observer = observer | ||
@disposed = false | ||
@disposable = nil | ||
end | ||
|
||
def dispose | ||
disposable = nil | ||
@observer.stop | ||
@gate.synchronize do | ||
unless @disposed | ||
@disposed = true | ||
disposable = @disposable | ||
end | ||
end | ||
|
||
unless disposable.nil? | ||
disposable.dispose | ||
end | ||
end | ||
|
||
def set(disposable) | ||
flag = false | ||
@gate.synchronize do | ||
unless @disposed | ||
@disposable = disposable | ||
else | ||
flag = true | ||
end | ||
end | ||
if flag | ||
disposable.dispose | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
require 'rx/abstract_observer' | ||
require 'rx/composite_disposable' | ||
|
||
module RX | ||
class AutoDetachObserver < RX::AbstractObserver | ||
def initialize(observer) | ||
@group = RX::CompositeDisposable.new | ||
@observer = observer | ||
end | ||
|
||
def add(disposable) | ||
@group.add(disposable) | ||
end | ||
|
||
def completed | ||
@observer.on_completed | ||
@group.dispose | ||
end | ||
|
||
def error(exception) | ||
@observer.on_error(exception) | ||
@group.dispose | ||
end | ||
|
||
def next(value) | ||
@observer.on_next(value) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class BooleanDisposable | ||
|
||
def initialize | ||
@is_disposed = false | ||
end | ||
|
||
def disposed? | ||
@is_disposed | ||
end | ||
|
||
def dispose | ||
@is_disposed = true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class CompositeDisposable | ||
|
||
def initialize(disposables = []) | ||
@disposables = disposables | ||
@disposed = false | ||
@gate = Mutex.new | ||
end | ||
|
||
def dispose | ||
currentDisposables = nil | ||
@gate.synchronize do | ||
unless @disposed | ||
@disposed = true | ||
currentDisposables = @disposables | ||
@disposables = [] | ||
end | ||
end | ||
unless currentDisposables.nil? | ||
currentDisposables.each {|disposable| disposable.dispose} | ||
end | ||
end | ||
|
||
def add(disposable) | ||
shouldDispose = false | ||
@gate.synchronize do | ||
shouldDispose = @disposed | ||
unless @disposed | ||
@disposables.push(disposable) | ||
end | ||
end | ||
if shouldDispose | ||
disposable.dispose | ||
end | ||
end | ||
|
||
def clear | ||
currentDisposables = nil | ||
@gate.synchronize do | ||
currentDisposables = @disposables | ||
@disposables = [] | ||
end | ||
currentDisposables.each {|disposable| disposable.dispose} | ||
end | ||
|
||
def count | ||
@disposables.length | ||
end | ||
|
||
def remove(disposable) | ||
should_dispose = false | ||
@gate.synchronize do | ||
should_dispose = @disposables.delete(disposable).dispose.nil? | ||
end | ||
if should_dispose | ||
disposable.dispose | ||
end | ||
should_dispose | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class Disposable | ||
|
||
def initialize(&disposable_action) | ||
@disposable_action = disposable_action | ||
@gate = Mutex.new | ||
@disposed = false | ||
end | ||
|
||
def dispose | ||
should_dispose = false | ||
@gate.synchronize do | ||
should_dispose = !@disposed | ||
end | ||
if should_dispose | ||
@disposable_action.call | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class EmptyDisposable | ||
def dispose | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root | ||
|
||
module RX | ||
class MutableDisposable | ||
|
||
def initialize | ||
@current = nil | ||
@disposed = false | ||
@gate = Mutex.new | ||
end | ||
|
||
def replace(disposable) | ||
shouldDispose = false | ||
@gate.synchronize do | ||
shouldDispose = @disposed | ||
unless shouldDispose | ||
unless @current.nil? | ||
@current.dispose | ||
end | ||
@current = disposable | ||
end | ||
end | ||
if shouldDispose && !disposable.nil? | ||
disposable.dispose | ||
end | ||
end | ||
|
||
def dispose | ||
@gate.synchronize do | ||
unless @disposed | ||
@disposed = true | ||
unless @current.nil? | ||
@current.dispose | ||
@current = nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.