Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

promise limit time

const longTask = () => new Promise(resolve =>
  setTimeout(() => resolve("Long task complete."), 300))

const timeout = (cb, interval) => () =>
  new Promise(resolve => setTimeout(() => cb(resolve), interval))

const onTimeout = timeout(resolve =>
  resolve("The 'maybeLongTask' ran too long!"), 200)

Promise.race([longTask, onTimeout].map(f => f())).then(console.log)
Comment

PREVIOUS NEXT
Code Example
Javascript :: Remove key from obj and save in diff obj 
Javascript :: timertask jquery 
Javascript :: OpenTok Create Session 
Javascript :: nodejs: express, morgan, mongoose package 
Javascript :: Javascript: take every nth Element of Array 
Javascript :: how to get html element coords in js 
Javascript :: change origin phaser 
Javascript :: node add dependency 
Javascript :: phaser place on rectangle shift 
Javascript :: phaser animation from png sequence 
Javascript :: phaser pause all animations 
Javascript :: test unitaire javascript 
Javascript :: Pretty-Print JSON within Neovim 
Javascript :: object destructuring in javascript 
Javascript :: string variable 
Javascript :: function Tom(a, b) { return a + b; } 
Javascript :: how to used xpath snapshot in loop 
Javascript :: react native geolocation 
Javascript :: ternary operators js 
Javascript :: schema 
Javascript :: regex and 
Javascript :: functions javascript 
Javascript :: constructer 
Javascript :: javascript sort array of objects by key value ascending and descending order 
Javascript :: js array split 
Javascript :: object.assign in express 
Javascript :: delegate in javascript 
Javascript :: variable name as a string in Javascript function 
Javascript :: curl to javascript fetch 
Javascript :: remove item from array 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =