coma coma - 1 year ago 83
Javascript Question

How to abort calls made by @cycle/http driver?

I'm pretty new to the whole Cycle.js/RxJS ecosystem and was hoping for someone to guide me on the process of aborting an ongoing ajax call since it looks like doable somehow.

It would be awesome to have a little example forked from the search-github-user one using this.

I'm adding here a copy from that example for the sake of avoiding SO zealots downvoting:

import Cycle from '@cycle/core';
import {Observable} from 'rx';
import {div, label, input, hr, ul, li, a, makeDOMDriver} from '@cycle/dom';
import {makeHTTPDriver} from '@cycle/http';

function main(sources) {
// Requests for Github repositories happen when the input field changes,
// debounced by 500ms, ignoring empty input field.
const searchRequest$ ='.field').events('input')
.map(ev =>
.filter(query => query.length > 0)
.map(q => ({
url: '' + encodeURI(q),
category: 'github',

// Requests unrelated to the Github search. This is to demonstrate
// how filtering for the HTTP response category is necessary.
const otherRequest$ = Observable.interval(1000).take(2)
.map(() => '');

// Convert the stream of HTTP responses to virtual DOM elements.
const vtree$ = sources.HTTP
.filter(res$ => res$.request.category === 'github')
.flatMap(x => x)
.map(res => res.body.items)
.map(results =>
label({className: 'label'}, 'Search:'),
input({className: 'field', attributes: {type: 'text'}}),
ul({className: 'search-results'}, =>
li({className: 'search-result'}, [
a({href: result.html_url},

const request$ = searchRequest$.merge(otherRequest$);

return {
DOM: vtree$,
HTTP: request$
}, {
DOM: makeDOMDriver('#main-container'),
HTTP: makeHTTPDriver()


Thanks to @user3743222 for pointing out the change on the master branch, it seems that the author has released a new version and now the abort part is here.

Answer Source

In current version, all the response$ streams get listened to immediately, so they never terminate before the request comes and aborting doesn't work effectively. There's an issue on that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download