How to use the observable-fns.Observable function in observable-fns

To help you get started, we’ve selected a few observable-fns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andywer / threads.js / test / workers / count-to-five.ts View on Github external
expose(function countToFive() {
  return new Observable(observer => {
    for (let counter = 1; counter <= 5; counter++) {
      observer.next(counter)
    }
    observer.complete()
  })
})
github andywer / threads.js / src / master / spawn.ts View on Github external
function createEventObservable(worker: WorkerType, workerTermination: Promise): Observable {
  return new Observable(observer => {
    const messageHandler = ((messageEvent: MessageEvent) => {
      const workerEvent: WorkerMessageEvent = {
        type: WorkerEventType.message,
        data: messageEvent.data
      }
      observer.next(workerEvent)
    }) as EventListener
    const rejectionHandler = ((errorEvent: PromiseRejectionEvent) => {
      debugThreadUtils("Unhandled promise rejection event in thread:", errorEvent)
      const workerEvent: WorkerInternalErrorEvent = {
        type: WorkerEventType.internalError,
        error: Error(errorEvent.reason)
      }
      observer.next(workerEvent)
    }) as EventListener
    worker.addEventListener("message", messageHandler)
github andywer / threads.js / src / master / invocation-proxy.ts View on Github external
function createObservableForJob(worker: WorkerType, jobUID: number): Observable {
  return new Observable(observer => {
    let asyncType: "observable" | "promise" | undefined

    const messageHandler = ((event: MessageEvent) => {
      debugMessages("Message from worker:", event.data)
      if (!event.data || event.data.uid !== jobUID) return

      if (isJobStartMessage(event.data)) {
        asyncType = event.data.resultType
      } else if (isJobResultMessage(event.data)) {
        if (asyncType === "promise") {
          if (typeof event.data.payload !== "undefined") {
            observer.next(event.data.payload)
          }
          observer.complete()
          worker.removeEventListener("message", messageHandler)
        } else {
github satoshipay / solar / src / workers / _util / subscription.ts View on Github external
export function subscribeToUpdatesAndPoll(
  implementation: SubscriberImplementation,
  options?: { retryFetchOnNoUpdate: boolean }
): Observable {
  const { retryFetchOnNoUpdate = true } = options || {}

  return multicast(
    new Observable(observer => {
      let cancelled = false

      let unsubscribe = () => {
        cancelled = true
      }

      const handleUnexpectedError = (error: Error) => {
        try {
          if (implementation.handleError) {
            implementation.handleError(error)
          } else {
            throw error
          }
        } catch (error) {
          observer.error(error)
        }

observable-fns

Light-weight observable implementation and utils written in TypeScript. Based on zen-observable.

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis