This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| step1() | |
| .then(result1 => step2(result1)) | |
| .then(result2 => step3(result2)) | |
| .then(result3 => step4(result3)) | |
| .then(result4 => console.log(result4)) | |
| .catch(error => throw error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function* g() { | |
| yield 1 | |
| yield 2 | |
| return (yield 3) + 1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const generator = g() | |
| generator.next() // { value: 1, done: false } | |
| generator.next() // { value: 2, done: false } | |
| generator.next() // { value: 3, done: false } | |
| generator.next(10) // { value: 11, done: true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function* g() { | |
| try { | |
| yield 1 // throws 'first error' | |
| } catch (error) { // catches 'first error' | |
| console.error('inside generator', error) | |
| } | |
| yield 2 // throws but does not catch 'second error' | |
| return 3 // never reached because exception thrown | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM alpine:latest | |
| COPY boost.patch /tmp | |
| COPY prepare.sh /tmp | |
| WORKDIR /tmp | |
| RUN ./prepare.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getFullName = async(function* (username, password) { | |
| let token | |
| try { | |
| token = yield logIn(username, password); | |
| } catch (error) { | |
| console.error('wrong username or password') | |
| return | |
| } | |
| const user = yield getUser(token) | |
| return user.fullName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getFullName(username, password) { | |
| let token | |
| try { | |
| token = await logIn(username, password); | |
| } catch (error) { | |
| console.error('wrong username or password') | |
| return | |
| } | |
| const user = await getUser(token) | |
| return user.fullName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const typeahead = fromEvent(searchBox, 'input').pipe( | |
| map((e: KeyboardEvent) => e.target.value), | |
| filter(text => text.length > 2), | |
| debounceTime(10), | |
| distinctUntilChanged(), | |
| switchMap(() => ajax('/api/endpoint')) | |
| ) | |
| typeahead.subscribe(data => { | |
| // Handle the data from the API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| from, | |
| Observable, | |
| ObservableInput, | |
| Observer, | |
| Subscriber, | |
| Subscription, | |
| } from 'rxjs' | |
| import { take } from 'rxjs/operators' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function async(makeGenerator) { | |
| // Return a function that constructs an Observable. | |
| return function(...args) { | |
| return Observable.create(observer => { | |
| // This function won't be called until the observable is subscribed. | |
| const generator = makeGenerator.apply(this, args) | |
| return new GeneratorSubscriber(observer, generator) | |
| }) | |
| } | |
| } |