Created
March 6, 2019 23:13
-
-
Save fvilante/ba5a9171e31a863601115b0ebc50c6ad to your computer and use it in GitHub Desktop.
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
namespace mapStream_ { | |
export interface EventGenerator { | |
onEvent: (h: EventHandler) => void | |
} | |
type Food = string | |
export type Event = Food | |
export type EventHandler = (f: Event) => void | |
const foodStream : EventGenerator = | |
{ | |
onEvent: (handler: EventHandler) => { | |
setTimeout( () => handler("galinha") , 1000 ) | |
setTimeout( () => handler("vaca") , 2000 ) | |
setTimeout( () => handler("milho"), 3000 ) | |
} | |
} | |
foodStream.onEvent( (food: Event):void => console.log(food) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment