Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Podwysocki mattpodwysocki

View GitHub Profile
View test_subscription.rb
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
module RX
# Records information about subscriptions to and unsubscriptions from observable sequences.
class TestSubscription
FIXNUM_MAX = (2**(0.size * 8 -2) -1)
attr_reader :subscribe, :unsubscribe
View notification.rb
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
require 'rx/concurrency/immediate_scheduler'
require 'rx/core/observable'
module RX
# Represents a notification to an observer.
module Notification
View synchronized_observer.rb
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
require 'monitor'
require 'rx/core/observer'
module RX
module Observer
class << self
View as_observer.rb
def as_observer
Observer.configure do |o|
o.on_next &method(:on_next)
o.on_error &method(:on_error)
o.on_completed &method(:on_completed)
end
end
View defer_test.rb
def test_defer_raise
scheduler = RX::TestScheduler.new
invoked = 0
err = 'foo'
res = scheduler.configure do
RX::Observable.defer do
invoked += 1
raise err
@mattpodwysocki
mattpodwysocki / scan.rb
Last active Aug 29, 2015
Observable.scan for incremental reduce
View scan.rb
# Applies an accumulator function over an observable sequence and returns each intermediate result.
# The optional seed value is used as the initial accumulator value.
# For aggregation behavior with no intermediate results, see Observable.reduce.
def scan(*args, &block)
has_seed = false
seed = nil
action = nil
# Argument parsing to support:
# 1. (seed, Symbol)
@mattpodwysocki
mattpodwysocki / buffering.js
Created Feb 14, 2014
Backpressure mechanisms in RxJS
View buffering.js
var source = Rx.Observable.interval(100).bufferWithTimeOrCount(500 /*ms*/, 50 /* items */);
source.subscribe(function (arr) {
// Have chunked array based upon time or count, whichever hits first
})
View amb.rb
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
require 'monitor'
require 'rx/subscriptions/subscription'
require 'rx/subscriptions/composite_subscription'
require 'rx/subscriptions/ref_count_subscription'
require 'rx/subscriptions/single_assignment_subscription'
require 'rx/core/observer'
require 'rx/core/observable'
View combine_latest.rb
# Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
def combine_latest(*args, &result_selector)
AnonymousObservable.new do |observer|
n = args.length
has_value = Array.new(n, false)
has_value_all = false
values = Array.new(n)
is_done = Array.new(n, false)
View from-promise.js
// Submit the form when the submit button is clicked
var signUpCommand = function(emailAddress) {
var promise = $.ajax({
type: 'POST',
url: '...',
data: JSON.stringify({
'email': emailAddress
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json'