// @flow
const setImmediate = (glob =>
  glob.setImmediate || ((fn, ...args) => glob.setTimeout(fn, 0, ...args)))(
  typeof window !== 'undefined' ? window : global,
);

export function schedule(fn: Function, args?: any[] = []): Promise<any> {
  return new Promise(resolve => {
    setImmediate(() => {
      const result = fn(...args);
      resolve(result);
    });
  });
}

export function delay(time: number): Promise<void> {
  return new Promise(resolve => {
    setTimeout(resolve, time);
  });
}

@@ -2,16 +2,214 @@
 / @flow%0A
+const getGlob = () =%3E %7B%0A  if (%0A    typeof window !== 'undefined' &&%0A    window.setImmediate &&%0A    window.setTimeout &&%0A    window.setTimeout.apply%0A  ) %7B%0A    return window;%0A  %7D%0A  return global;%0A%7D;%0A%0A
 const se
@@ -230,16 +230,16 @@
 glob =%3E%0A
-
   glob.s
@@ -312,55 +312,17 @@
 (%0A  
-typeof window !== 'undefined' ? window : global
+getGlob()
 ,%0A);

Fix issue #255