@@ -1187,16 +1187,60 @@ update(PotInternal, {
1187
1187
* @ignore
1188
1188
* @based JSDeferred.next
1189
1189
*/
1190
- flush : function ( callback ) {
1191
- var handler = this . byEvent || this . byTick || this . byTimer ;
1192
- handler ( callback ) ;
1190
+ flush : function ( ) {
1191
+ ( this . byTick || this . byImmediate ||
1192
+ this . byMessage || this . byEvent ||
1193
+ this . byTimer ) ( callback ) ;
1193
1194
} ,
1195
+ /**
1196
+ * @private
1197
+ * @ignore
1198
+ */
1199
+ byMessage : function ( ) {
1200
+ var channel , queue ;
1201
+ if ( typeof MessageChannel !== 'function' ) {
1202
+ return false ;
1203
+ }
1204
+ try {
1205
+ channel = new MessageChannel ( ) ;
1206
+ if ( ! channel . port1 || ! channel . port2 ) {
1207
+ throw false ;
1208
+ }
1209
+ queue = [ ] ;
1210
+ /**@ignore */
1211
+ channel . port1 . onmessage = function ( ) {
1212
+ queue . shift ( ) ( ) ;
1213
+ } ;
1214
+ } catch ( e ) {
1215
+ return false ;
1216
+ }
1217
+ return function ( callback ) {
1218
+ queue . push ( callback ) ;
1219
+ channel . port2 . postMessage ( '' ) ;
1220
+ } ;
1221
+ } ( ) ,
1222
+ /**
1223
+ * @private
1224
+ * @ignore
1225
+ */
1226
+ byImmediate : function ( ) {
1227
+ if ( typeof setImmediate !== 'function' ) {
1228
+ return false ;
1229
+ }
1230
+ return function ( callback ) {
1231
+ try {
1232
+ setImmediate ( callback ) ;
1233
+ } catch ( e ) {
1234
+ ( this . byImmediate = this . byTimer ) ( callback ) ;
1235
+ }
1236
+ } ;
1237
+ } ( ) ,
1194
1238
/**
1195
1239
* @private
1196
1240
* @ignore
1197
1241
* @based JSDeferred.next
1198
1242
*/
1199
- byEvent : ( function ( ) {
1243
+ byEvent : function ( ) {
1200
1244
var IMAGE ;
1201
1245
if ( PotSystem . isNonBrowser || PotSystem . isNodeJS ||
1202
1246
typeof window !== 'object' || typeof document !== 'object' ||
@@ -1234,15 +1278,15 @@ update(PotInternal, {
1234
1278
try {
1235
1279
img . src = IMAGE ;
1236
1280
} catch ( e ) {
1237
- this . byEvent = this . byTimer ;
1281
+ ( this . byEvent = this . byTimer ) ( callback ) ;
1238
1282
}
1239
1283
} ;
1240
- } ( ) ) ,
1284
+ } ( ) ,
1241
1285
/**
1242
1286
* @private
1243
1287
* @ignore
1244
1288
*/
1245
- byTick : ( function ( ) {
1289
+ byTick : function ( ) {
1246
1290
if ( ! PotSystem . isNodeJS || typeof process !== 'object' ||
1247
1291
typeof process . nextTick !== 'function' ) {
1248
1292
return false ;
@@ -1251,7 +1295,7 @@ update(PotInternal, {
1251
1295
return function ( callback ) {
1252
1296
process . nextTick ( callback ) ;
1253
1297
} ;
1254
- } ( ) ) ,
1298
+ } ( ) ,
1255
1299
/**
1256
1300
* @private
1257
1301
* @ignore
0 commit comments