/**
  * Checks all connections, and raises an exception if any connection has not received a response.
  *
  * This method only exists in the mock implementation, not in real Backends.
  * @return {?}
  */
 verifyNoPendingRequests() {
     /** @type {?} */
     let pending = 0;
     this.pendingConnections.subscribe((c) => pending++);
     if (pending > 0)
         throw new Error(`${pending} pending connections to be resolved`);
 }
Example #2
0
  constructor() {
    this._states = new Subject();
    this._states.subscribe(state => { this.state = state; });

    // Create an observable that contains the current, and all future, states. Since the initial
    // state is set directly (assigned to `this.state`), we can't just use a ReplaySubject
    // TODO: Use a computed property key when that's supported.
    (this: any)[$$observable] = () => Observable.of(this.state).concat(this._states);
  }
Example #3
0
setTimeout(() => {
  //closeClick$.withLastestFrom(response$
  subject.subscribe(
    (value) => console.log(`subscribeXX ${value}`),
    (err) => console.log(`subscribeXX error ${err}`),
    () => console.log(`completeXX`)
  );
  
}, 5000);
Example #4
0
 // Subject<MockConnection>
 constructor() {
     this.connectionsArray = [];
     this.connections = new Subject();
     this.connections.subscribe((/**
      * @param {?} connection
      * @return {?}
      */
     (connection) => this.connectionsArray.push(connection)));
     this.pendingConnections = new Subject();
 }
Example #5
0
  constructor() {
    this._buffers = new Map();
    this._fileEvents = new Subject();
    this._directoryEvents = new BehaviorSubject(new Set());
    this._requests = new FileVersionNotifier();

    this._resources = new UniversalDisposable();
    this._resources.add(this._requests);
    this._resources.add(this._fileEvents.subscribe(event => { this._requests.onEvent(event); }));
  }
Example #6
0
  constructor(rawState: ?Object) {
    const action$ = new Rx.Subject();
    const initialState = deserializeAppState(rawState);
    this._state$ = new Rx.BehaviorSubject(initialState);
    createStateStream(
      action$.asObservable(),
      initialState,
    )
      .sampleTime(100)
      .subscribe(this._state$);
    this._commands = new Commands(
      action$,
      () => this._state$.getValue(),
    );
    this._outputService = new OutputService(this._commands);
    this._disposables = new CompositeDisposable(
      atom.contextMenu.add({
        '.nuclide-console-record': [
          {
            label: 'Copy Message',
            command: 'nuclide-console:copy-message',
          },
        ],
      }),
      atom.commands.add(
        '.nuclide-console-record',
        'nuclide-console:copy-message',
        event => {
          const el = event.target;
          if (el == null || el.innerText == null) {
            return;
          }
          atom.clipboard.write(el.innerText);
        },
      ),
      featureConfig.observe(
        'nuclide-console.maximumMessageCount',
        maxMessageCount => this._commands.setMaxMessageCount(maxMessageCount),
      ),

      // Action side-effects
      new DisposableSubscription(
        action$.subscribe(action => {
          if (action.type !== ActionTypes.EXECUTE) {
            return;
          }
          const {executorId, code} = action.payload;
          const executors = this._state$.getValue().executors;
          const executor = executors.get(executorId);
          invariant(executor);
          executor.execute(code);
        })
      ),
    );
  }
Example #7
0
 constructor(initialState: ?SwiftPMTaskRunnerStoreState) {
   this.id = 'swiftpm';
   this.name = 'Swift';
   this._initialState = initialState;
   this._projectRoot = new Subject();
   this._disposables = new UniversalDisposable(
     this._projectRoot.subscribe(path =>
       this._getFlux().actions.updateProjectRoot(path),
     ),
   );
 }
Example #8
0
 constructor(sendMessageToClient: (message: Object) => void) {
   this._connections = new Set();
   this._sendMessageToClient = message => sendMessageToClient(message);
   this._freshConnectionId = 0;
   this._newConnections = new Subject();
   this._breakpointManager = new BreakpointManager(this._sendMessageToClient.bind(this));
   this._disposables = new UniversalDisposable(
     this._newConnections.subscribe(this._handleNewConnection.bind(this)),
     this._breakpointManager,
   );
 }
Example #9
0
  constructor(execInfoContainer: FlowExecInfoContainer) {
    this._execInfoContainer = execInfoContainer;
    this._disposed = false;
    this._flowRootMap = new Map();

    // No need to dispose of this subscription since we want to keep it for the entire life of this
    // object. When this object is garbage collected the subject should be too.
    this._flowRoot$ = new Subject();
    this._flowRoot$.subscribe(flowRoot => {
      this._flowRootMap.set(flowRoot.getPathToRoot(), flowRoot);
    });
  }
Example #10
0
 return this._platform.isBrowser ? Observable.create(observer => {
     if (!this._globalSubscription) {
         this._addGlobalListener();
     }
     // In the case of a 0ms delay, use an observable without auditTime
     // since it does add a perceptible delay in processing overhead.
     const /** @type {?} */ subscription = auditTimeInMs > 0 ?
         this._scrolled.pipe(auditTime(auditTimeInMs)).subscribe(observer) :
         this._scrolled.subscribe(observer);
     this._scrolledCount++;
     return () => {
         subscription.unsubscribe();
         this._scrolledCount--;
         if (!this._scrolledCount) {
             this._removeGlobalListener();
         }
     };
 }) : of();
Example #11
0
function onPropUpdated(synapse, dotted_path, callback, dispose) {  

  var js_path = dotted_path;

  if (js_path[0] != '.') {
    js_path = '.'+js_path;
  }

  var watch_path = dotted_path.split('.').filter(function(part) {
    return (part && true);
  });

  // Subscription
  var subscription = subject.subscribe(function(updated_path) {

    var match = true;
    for (var i=0, ii=watch_path.length, iii = updated_path.length; i<ii; i++) {      
      if (watch_path[i] != undefined && updated_path[i] != undefined && watch_path[i] != updated_path[i]) {
        match = false;
        break;
      }
      else if (i == iii-1) {
        break;
      }
    }

    if (match) {
      var res = JSPath.apply(js_path, synapse);

      if (res.length == 1) { res = res[0]; }
      else if (res.length == 0) { res = undefined; }

      if (res) {
        callback(res);   
        if (dispose) {
          subscription.dispose();
        }            
      }
    }

  });

  return subscription;
}
Example #12
0
  constructor(state: ?Object) {
    this._toggleEvents = new Subject();
    this._shouldRenderDiagnostics = this._toggleEvents.scan(prev => !prev, false);

    this._disposables = new CompositeDisposable();
    this._activeEditorRegistry = new ActiveEditorRegistry(
      resultFunction,
      {updateOnEdit: false},
    );

    this._disposables.add(
      atom.commands.add(
        'atom-workspace',
        'nuclide-type-coverage:toggle-inline-display',
        () => this._toggleEvents.next(),
      ),
    );

    this._disposables.add(new DisposableSubscription(
        this._toggleEvents.subscribe(() => track('nuclide-type-coverage:toggle')),
      ),
    );
  }
Example #13
0
 const saveEvents = Observable.create(observer => {
   const realSave = editor.save;
   const newSaves = new Subject();
   // HACK: intercept the real TextEditor.save and handle it ourselves.
   // Atom has no way of injecting content into the buffer asynchronously
   // before a save operation.
   // If we try to format after the save, and then save again,
   // it's a poor user experience (and also races the text buffer's reload).
   const editor_ = (editor: any);
   editor_.save = () => {
     newSaves.next('new-save');
     return this._safeFormatCodeOnSave(editor)
       .takeUntil(newSaves)
       .toPromise()
       .then(() => realSave.call(editor));
   };
   const subscription = newSaves.subscribe(observer);
   return () => {
     // Restore the save function when we're done.
     editor_.save = realSave;
     subscription.unsubscribe();
   };
 });
 constructor() {
     this.connectionsArray = [];
     this.connections = new Subject();
     this.connections.subscribe((connection) => this.connectionsArray.push(connection));
     this.pendingConnections = new Subject();
 }
Example #15
0
"use strict";
var Rx = require("rxjs");

var subject = new Rx.Subject();

subject.subscribe({
	next: v => {
		console.log("observerA: %j", v);
	},
	error: err => {
		console.error("errorA: %j", err);
	},
	complete: () => {
		console.log("doneA");
	}
});

subject.subscribe({
	next: v => {
		console.log("observerB: %j", v);
	},
	error: err => {
		console.error("errorB: %j", err);
	},
	complete: () => {
		console.log("doneB");
	}
});

subject.next({a: 10});
subject.next(2);
Example #16
0
          clearInterval(inter);
          obs.complete();
        }
    }, time);
  }); 
;

const stream1 = createStream(2, 1000).map(v => `stream1: ${v}`);
const stream2 = createStream(4, 500).map(v => `stream1: ${v}`);

const stream3 = stream1.merge(stream2);

const subject = new Rx.Subject();

stream3.subscribe(subject);

subject.subscribe(
  (value) => console.log(`subscribe ${value}`),
  (err) => console.log(`subscribe error ${err}`),
  () => console.log(`complete`)
);

setTimeout(() => {
  //closeClick$.withLastestFrom(response$
  subject.subscribe(
    (value) => console.log(`subscribeXX ${value}`),
    (err) => console.log(`subscribeXX error ${err}`),
    () => console.log(`completeXX`)
  );
  
}, 5000);
 return new rxjs_1.Observable(subject => {
     // Handle input.
     inboundBus.subscribe(message => {
         switch (message.kind) {
             case api_1.JobInboundMessageKind.Ping:
                 subject.next({ kind: api_1.JobOutboundMessageKind.Pong, description, id: message.id });
                 break;
             case api_1.JobInboundMessageKind.Stop:
                 // There's no way to cancel a promise or a synchronous function, but we do cancel
                 // observables where possible.
                 if (subscription) {
                     subscription.unsubscribe();
                 }
                 subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
                 subject.complete();
                 // Close all channels.
                 channels.forEach(x => x.complete());
                 break;
             case api_1.JobInboundMessageKind.Input:
                 inputChannel.next(message.value);
                 break;
         }
     });
     // Configure a logger to pass in as additional context.
     const logger = new index_2.Logger('job');
     logger.subscribe(entry => {
         subject.next({
             kind: api_1.JobOutboundMessageKind.Log,
             description,
             entry,
         });
     });
     // Execute the function with the additional context.
     subject.next({ kind: api_1.JobOutboundMessageKind.Start, description });
     const channels = new Map();
     const newContext = Object.assign({}, context, { input: inputChannel.asObservable(), logger,
         createChannel(name) {
             if (channels.has(name)) {
                 throw new ChannelAlreadyExistException(name);
             }
             const channelSubject = new rxjs_1.Subject();
             channelSubject.subscribe(message => {
                 subject.next({
                     kind: api_1.JobOutboundMessageKind.ChannelMessage, description, name, message,
                 });
             }, error => {
                 subject.next({ kind: api_1.JobOutboundMessageKind.ChannelError, description, name, error });
                 // This can be reopened.
                 channels.delete(name);
             }, () => {
                 subject.next({ kind: api_1.JobOutboundMessageKind.ChannelComplete, description, name });
                 // This can be reopened.
                 channels.delete(name);
             });
             channels.set(name, channelSubject);
             return channelSubject;
         } });
     const result = fn(argument, newContext);
     // If the result is a promise, simply wait for it to complete before reporting the result.
     if (index_3.isPromise(result)) {
         result.then(result => {
             subject.next({ kind: api_1.JobOutboundMessageKind.Output, description, value: result });
             subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
             subject.complete();
         }, err => subject.error(err));
     }
     else if (rxjs_1.isObservable(result)) {
         subscription = result.subscribe((value) => subject.next({ kind: api_1.JobOutboundMessageKind.Output, description, value }), error => subject.error(error), () => {
             subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
             subject.complete();
         });
         return subscription;
     }
     else {
         // If it's a scalar value, report it synchronously.
         subject.next({ kind: api_1.JobOutboundMessageKind.Output, description, value: result });
         subject.next({ kind: api_1.JobOutboundMessageKind.End, description });
         subject.complete();
     }
 });
Example #18
0
	subscribe: listener => consoleListener.subscribe({next: listener})
Example #19
0
 observable = new LoggerObservable(observer => {
     return events.subscribe(observer);
 });
Example #20
0
 __Synapse.updated = function(callback) {
   return subject.subscribe(callback);
 }
Example #21
0
 subscribe(action) {
   const subscription = this.rxSubject.subscribe(action);
   this.rxSubject.next(this.version);
   return subscription;
 }
 /**
  * @param {?} fn
  * @return {?}
  */
 onHashChange(fn) { this.hashUpdate.subscribe(fn); }
 /**
  * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  * connections, if it's expected that there are connections that have not yet received a response.
  *
  * This method only exists in the mock implementation, not in real Backends.
  * @return {?}
  */
 resolveAllConnections() { this.connections.subscribe((c) => c.readyState = 4); }
Example #24
0
 /**
  * Can be used in conjunction with `verifyNoPendingRequests` to resolve any not-yet-resolve
  * connections, if it's expected that there are connections that have not yet received a response.
  *
  * This method only exists in the mock implementation, not in real Backends.
  * @return {?}
  */
 resolveAllConnections() { this.connections.subscribe((/**
  * @param {?} c
  * @return {?}
  */
 (c) => c.readyState = 4)); }
Example #25
0
 subscribe(observerOrNext, error, complete) {
     let subscription = this.resultsSubject.subscribe(observerOrNext);
     let resultsSubscription = new ResultsSubscription(subscription, this.resultsUnsubscribeCallback);
     return resultsSubscription;
 }
Example #26
0
const vm = require('vm');
const Rx = require('rxjs');
const scenarioApiManager = require('./scenario-api.manager');

const inputStream = new Rx.Subject();
const outputStream = new Rx.Subject();

//0 comand arg is node, 1 is path to file
const ARGV_SCRIPT_INDEX = 2;

outputStream.subscribe((data) => {
    process.send({
        type: 'message',
        content: data
    });
});

const SMART_HOUSE = scenarioApiManager.create(inputStream, outputStream);

const sandbox = {
    setTimeout,
    console,
    SMART_HOUSE
};

vm.runInNewContext(process.argv[ARGV_SCRIPT_INDEX], sandbox);