Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: fromPromise support promise cancelable? #5958

Closed
imcuttle opened this issue Jan 17, 2021 · 1 comment
Closed

Feat: fromPromise support promise cancelable? #5958

imcuttle opened this issue Jan 17, 2021 · 1 comment

Comments

@imcuttle
Copy link

imcuttle commented Jan 17, 2021

function fromPromise<T>(promise: PromiseLike<T>) {
return new Observable((subscriber: Subscriber<T>) => {
promise
.then(
(value) => {
if (!subscriber.closed) {
subscriber.next(value);
subscriber.complete();
}
},
(err: any) => subscriber.error(err)
)
.then(null, reportUnhandledError);
});
}

I saw the soure code of fromPromise to Observable, Why not support promise cancelable?

 function fromPromise<T>(promise: PromiseLike<T>) { 
   return new Observable((subscriber: Subscriber<T>) => { 
     promise 
       .then( 
         (value) => { 
           if (!subscriber.closed) { 
             subscriber.next(value); 
             subscriber.complete(); 
           } 
         }, 
         (err: any) => subscriber.error(err) 
       ) 
       .then(null, reportUnhandledError); 
   }); 
   return () => {
     // See https://github.com/sindresorhus/p-cancelable/blob/master/index.js
     if (promise && typeof promise.cacel === 'function') {
       if (!promise.isCanceled) {
            promise.cacel();
       }
     }
   };
 } 
@kwonoj
Copy link
Member

kwonoj commented Jan 17, 2021

There is discussion around to support spec-compliant abort signal (#5863). Rxjs don't support non-spec compliant cancel from 3rd party libraries.

@kwonoj kwonoj closed this as completed Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants