Skip to content

Instantly share code, notes, and snippets.

View mattpodwysocki's full-sized avatar

Matthew Podwysocki mattpodwysocki

View GitHub Profile
# 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
# 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
# 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
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
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 August 29, 2015 13:56
Observable.scan for incremental reduce
# 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 February 14, 2014 21:54
Backpressure mechanisms in RxJS
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
})
# 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'
# 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)
// 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'