Skip to content

Instantly share code, notes, and snippets.

@fvilante
Created March 6, 2019 23:13
Show Gist options
  • Save fvilante/ba5a9171e31a863601115b0ebc50c6ad to your computer and use it in GitHub Desktop.
Save fvilante/ba5a9171e31a863601115b0ebc50c6ad to your computer and use it in GitHub Desktop.
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