Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expose(function countToFive() {
return new Observable(observer => {
for (let counter = 1; counter <= 5; counter++) {
observer.next(counter)
}
observer.complete()
})
})
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)
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 {
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)
}