å¥ã®Webããã»ã¹ãšããŠãå®è¡ãããWebã¯ãŒã«ãŒãšããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã¯å¥ãšããŠãWindowsã¹ãã¢ã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®JavaScriptã³ãŒãã¯ãäžè¬çãªããããUIã¹ã¬ããã§å®è¡ãããŸãã ãã®ã³ãŒãã¯ãå¥ã ã®ã¹ã¬ããã§æäœãå®è¡ããéåæWinRT APIåŒã³åºããè¡ãããšãã§ããŸãããçæãã¹ãéèŠãªç¹ã1ã€ãããŸãããããã®éUIã¹ã¬ããããã®çµæã¯ãåŠçã®ããã«UIã¹ã¬ããã«è¿ãããŸãã ã€ãŸããäžé£ã®WinRTéåæåŒã³åºãïŒHTTPèŠæ±ãªã©ïŒãäžåºŠã«ãã¹ãŠéå§ãããšãçµæãã»ãŒåæã«UIã¹ããªãŒã ãããªãŒããŒããŒããããå¯èœæ§ããããŸãã ããã«ããŠãŒã¶ãŒïŒãŸãã¯WinJSïŒãDOMã«èŠçŽ ãè¿œå ããããUIã¹ããªãŒã ã®ããŒãžã¬ã€ã¢ãŠãã®æŽæ°ãå¿ èŠãšããã¹ã¿ã€ã«ãå€æŽããããããšãCPUãªãœãŒã¹ã奪ãåãã¿ã¹ã¯ãããã«å¢ããŸãã ãã®çµæãã¢ããªã±ãŒã·ã§ã³ã¯ããã¬ãŒããç¶æ ã«ãªããå¿çããªããªããŸãã
Windows 8ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã¯ãã®ãããªåœ±é¿ãæžããããã«ããã€ãã®æé ãå®è¡ã§ããŸããããšãã°ãã¿ã€ã ãããã¯å ã§éåææäœãå®è¡ããŠUIã¹ããªãŒã ãžã®æ»ãã®é »åºŠãå¶åŸ¡ããããããŒãžã®æŽæ°ãµã€ã¯ã«ãå¿ èŠãšããã¿ã¹ã¯ãçµã¿åãããŠ1åã®ãã¹ã§ããå€ãã®æäœãå®äºãããã§ããŸãã Windows 8.1ããã¯ãUIã¹ããªãŒã å ã§çŽæ¥ãç°ãªãã¿ã¹ã¯ã«åªå é äœãä»ããããšãå¯èœã«ãªããŸããã
ã¢ããªã±ãŒã·ã§ã³ãã¹ãã¯äœã¬ãã«ã¹ã±ãžã¥ãŒã©APIïŒ MSApp.executeAtPriority ïŒãæäŸããŸããã 代ããã«WinJS.Utilities.Scheduler APIã䜿çšããããšããå§ãããŸãã ãã®æšå¥šã®çç±ã¯ãWinJSããã®ã¹ã±ãžã¥ãŒã©APIãä»ããŠã¿ã¹ã¯ã管çããããã§ããããã¯ãåæ§ã®æ¹æ³ã§ç®¡çããäœæ¥ãWinJSãè¡ãäœæ¥ãšé©åã«èª¿æŽãããããšãæå³ããŸãã WinJSã¹ã±ãžã¥ãŒã©ã¯ãç¹ã«ãããã¹ã§ã®äœæ¥ã«é¢ããŠã¯ãããã»ã¹å šäœãžã®ã·ã³ãã«ãªã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããŸãã
ã¹ã±ãžã¥ãŒã©ã䜿çšããå¿ èŠããªãããšã«æ³šæããããšãéèŠã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ã調æŽããã®ã«åœ¹ç«ã¡ã人çãè€éã«ããããšã¯ãããŸããïŒ ãŸããã¹ã±ãžã¥ãŒã©ã§äœ¿çšãããããŸããŸãªåªå 床ãèŠãŠã¿ãŸãããã次ã«ããããã®åªå 床ã«åºã¥ããŠäœæ¥ãèšç»ããã³ç®¡çããæ¹æ³ãèŠãŠãããŸãã
ã¹ã±ãžã¥ãŒã©ã䜿çšããå¿ èŠããªãããšã«æ³šæããããšãéèŠã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ã調æŽããã®ã«åœ¹ç«ã¡ã人çãè€éã«ããããšã¯ãããŸããïŒ ãŸããã¹ã±ãžã¥ãŒã©ã§äœ¿çšãããããŸããŸãªåªå 床ãèŠãŠã¿ãŸãããã次ã«ããããã®åªå 床ã«åºã¥ããŠäœæ¥ãèšç»ããã³ç®¡çããæ¹æ³ãèŠãŠãããŸãã
ã¹ã±ãžã¥ãŒã©ãŒã®åªå é äœ
WinJSã®çžå¯Ÿçãªåªå 床ã¯ã Scheduler.Priorityåæã§ç€ºãããŸãã éé 㧠ã max ã high ã aboveNormal ã normal ïŒã¢ããªã±ãŒã·ã§ã³ã³ãŒãã®ããã©ã«ãå€ïŒã belowNormal ã idleããã³minã§ãã 以äžã¯ãããããæé©ã«äœ¿çšããæ¹æ³ã«é¢ããäžè¬çãªã¬ã€ãã§ãã
- maxãhigh-ã¬ã³ããªã³ã°ããã»ã¹äžã«ããŒãžã®ã¬ã³ããªã³ã°ããã»ãŒãžãšéè€ãããããæ¬åœã«é«ãåªå 床ãæã€ã¿ã¹ã¯ã«ã¯æ§ããã«äœ¿çšããŸãã ãããã®åªå 床ãããŸãã«ãç©æ¥µçã«äœ¿çšãããšãã¢ããªã±ãŒã·ã§ã³ã®å¿çãé ããªãå ŽåããããŸãã
- aboveNormalãnormalãbelowNormal-æãéèŠãªã¿ã¹ã¯ã®çžå¯ŸçãªéèŠæ§ã瀺ãããã«äœ¿çšããŸãã
- idleãmin-UIã«äŸåé¢ä¿ã課ããªãé·æå®è¡ã¿ã¹ã¯ãŸãã¯ãµããŒãã¿ã¹ã¯ã«äœ¿çšããŸãã
ã³ãŒãã§ã¹ã±ãžã¥ãŒã©ã䜿çšããå¿ èŠã¯ãããŸããããéåææäœã®äœ¿çšãå°ãåæãããšãåªå é äœä»ãã倧ããªåœ¹å²ãæããå Žæãæããã«ãªãå¯èœæ§ããããŸãã ããšãã°ãã¹ãã©ãã·ã¥ã¹ã¯ãªãŒã³ã¯å®çŸ©äžã€ã³ã¿ã©ã¯ãã£ãã§ã¯ãªããããã¹ãã©ãã·ã¥ã¹ã¯ãªãŒã³ã®è¡šç€ºäžã«éUIæäœãåªå ããããã»ã«ã³ããªãªã¯ãšã¹ããbelowNormalã«èšå®ããªããæ倧ãŸãã¯é«åªå 床ã§æãéèŠãªHTTPãªã¯ãšã¹ããéä¿¡ãããã§ããŸãã ããã¯ããŠãŒã¶ãŒãã³ã³ãã³ããšå¯Ÿè©±ããå¯èœæ§ãæåŸ ããŠããããŒã ããŒãžãæç»ãããåã«ããããã®æåã®èŠæ±ãåŠçããã®ã«åœ¹ç«ã¡ãŸãããã®åŸãããã¯ã°ã©ãŠã³ãã§2次èŠæ±ã解決ã§ããŸãã ãã¡ããããŠãŒã¶ãŒãã»ã«ã³ããªã³ã³ãã³ããå¿ èŠãªããŒãžã«ç§»åããå Žåããã®ã¿ã¹ã¯ã®åªå 床ãaboveNormalãŸãã¯highã«å€æŽã§ããŸãã
WinJSã©ã€ãã©ãªèªäœã¯ãåªå é äœä»ããç©æ¥µçã«äœ¿çšããŸãã ããšãã°ããœãŒã¹å€æŽãããã¯ã解決ããŠããŒã¿ãé«ãåªå 床ã§ãã€ã³ãããã¯ãªãŒãã³ã°ã¿ã¹ã¯ã®ã¹ã±ãžã¥ãŒãªã³ã°ãåªå 床idleã§å®è¡ããŸãã ListViewãªã©ã®è€éãªã³ã³ãããŒã«ã§ã¯ãListViewã®å¯èŠéšåãã¬ã³ããªã³ã°ããããã«å¿ èŠãªæ°ããèŠçŽ ã®èŠæ±ã¯æé«ã®åªå 床ã§è¡ãããå¯èŠèŠçŽ ã®ã¬ã³ããªã³ã°ã¯aboveNormalã§è¡ããã次ã®èŠçŽ ã®ããŒãžã®èªã¿èŸŒã¿ ïŒé æ¹åïŒã¯éåžžã«è¡ãããŸã ïŒãŠãŒã¶ãŒãã¹ã¯ããŒã«ãããšããä»®å®ã®äžã§ïŒããã«ïŒãåã®ããŒãžã®ããªããŒãïŒéããŒãžã³ã°ã®å ŽåïŒã¯belowNormalã§è¡ãããŸã ã
ã¹ã±ãžã¥ãŒãªã³ã°ãšã¿ã¹ã¯ç®¡ç
ã¹ã±ãžã¥ãŒã©ãŒã®åªå é äœãããã£ãã®ã§ãUIã¹ã¬ããã§ã³ãŒããéåæã«å®è¡ããããã«å¿ èŠãªåªå é äœãæå®ããããšãã§ããŸãã ãããè¡ãã«ã¯ã Scheduler.scheduleã¡ãœãããåŒã³åºããŸãïŒããã©ã«ãã®åªå é äœã¯normalã§ã ïŒã ãã®ã¡ãœããã䜿çšãããšãé¢æ°å ã§ãããšããŠäœ¿çšãããªãã·ã§ã³ã®ãªããžã§ã¯ããšããã°ããã³èšºæã«äœ¿çšããååãæå®ã§ããŸãã ïŒ Scheduler.execHighã¡ãœããã¯ãåªå 床Priority.highã® MSApp.execAtPriorityãžã®çŽæ¥åŒã³åºããžã®çãåç §ã§ãããã®ã¡ãœããã¯è¿œå ã®åŒæ°ãåããŸãããïŒ
ç°¡åãªäŸãšããŠã HTMLã¹ã±ãžã¥ãŒã©ãŒã®äŸã®ã·ããªãª1ã§ã¯ãã¹ã±ãžã¥ãŒã©ãŒã«ãã©ã³ãã ïŒjs / schedulesjobscenario.jsïŒã®ç°ãªãåªå é äœãæã€äžé£ã®é¢æ°ãè¿œå ããŸã ã
window.output("\nScheduling Jobs..."); var S = WinJS.Utilities.Scheduler; S.schedule(function () { window.output("Running job at aboveNormal priority"); }, S.Priority.aboveNormal); window.output("Scheduled job at aboveNormal priority"); S.schedule(function () { window.output("Running job at idle priority"); }, S.Priority.idle, this); window.output("Scheduled job at idle priority"); S.schedule(function () { window.output("Running job at belowNormal priority"); }, S.Priority.belowNormal); window.output("Scheduled job at belowNormal priority"); S.schedule(function () { window.output("Running job at normal priority"); }, S.Priority.normal); window.output("Scheduled job at normal priority"); S.schedule(function () { window.output("Running job at high priority"); }, S.Priority.high); window.output("Scheduled job at high priority"); window.output("Finished Scheduling Jobs\n");
çµæãŠã£ã³ããŠã«ã¯ããã¿ã¹ã¯ããåŒã³åºããããšãäºæ³ãããé åºã§å®è¡ãããããšã瀺ãããŸãã
Scheduling Jobs... Scheduled job at aboveNormalPriority Scheduled job at idlePriority Scheduled job at belowNormalPriority Scheduled job at normalPriority Scheduled job at highPriority Finished Scheduling Jobs Running job at high priority Running job at aboveNormal priority Running job at normal priority Running job at belowNormal priority Running job at idle priority
ãããããªãã«ãšã£ãŠé©ãã§ã¯ãªãããšãé¡ã£ãŠããŸãïŒ
ã¹ã±ãžã¥ãŒã«ã¡ãœãããåŒã³åºããšã Scheduler.IJobã€ã³ã¿ãŒãã§ã€ã¹ãæºãããªããžã§ã¯ããè¿ãããŸããããã«ããã次ã®ã¡ãœãããšããããã£ãå®çŸ©ãããŸãã
ããããã£
- id-ïŒèªã¿åãå°çšïŒã¹ã±ãžã¥ãŒã©ãŒã«ãã£ãŠå²ãåœãŠãããäžæã®IDã
- name-ïŒèªã¿æžãå¯èœïŒã¢ããªã±ãŒã·ã§ã³ã«ãã£ãŠæäŸãããã¿ã¹ã¯ã®ååïŒæå®ãããŠããå ŽåïŒïŒscheduleã¡ãœããã®name-attributeïŒã
- priority-ïŒèªã¿åã/æžã蟌ã¿ïŒã¹ã±ãžã¥ãŒã©ãŒã«ã¢ã¯ã»ã¹ãããšãã«å²ãåœãŠãããåªå é äœã ããããã£ãèšå®ãããšãåªå 床ãå€æŽãããŸãã
- completed-ïŒèªã¿åãå°çšïŒã¿ã¹ã¯ãå®äºãããã©ããã瀺ãããŒã«å€ïŒã¹ã±ãžã¥ãŒã©ãŒã«æž¡ãããé¢æ°ãå®äºãããã¹ãŠã®äŸåããéåæã¿ã¹ã¯ãå®äºããŸãïŒã
- owner-ïŒèªã¿åã/æžã蟌ã¿ïŒã¿ã¹ã¯ãã°ã«ãŒãåããããã«äœ¿çšãããææè å±æ§ã ããã©ã«ãã§ã¯å®çŸ©ãããŠããŸããã
æ¹æ³
- pause-ã¿ã¹ã¯ã®ãããªãå®è¡ãåæ¢ããŸãã
- resume-以åã«äžæåæ¢ããã¿ã¹ã¯ãèµ·åããŸãïŒã¿ã¹ã¯ãåæ¢ããŠããªãå Žåã¯å¹æããããŸããïŒã
- cancel-ã¹ã±ãžã¥ãŒã©ãŒããã¿ã¹ã¯ãåé€ããŸãã
å®éã«ã¯ãåªå 床ã®äœãã¿ã¹ã¯ãã¹ã±ãžã¥ãŒã«ããŠããããã¬ã³ããªã³ã°ã®éå§åã«ã¿ã¹ã¯ãå®äºããå¿ èŠãããããŒãžã«ç§»åããå Žåã¯ã åªå 床ããããã£ãæŽæ°ããã ãã§ãïŒãããŠãããã«ãããããã«ã¹ã±ãžã¥ãŒã©ãã¯ãªã¢ããŸãïŒã åæ§ã«ãããŒãžã§äœããã®äœæ¥ãèšç»ããŠããŠãå¥ã®å Žæã«ç§»åãããšãã«ç¶ç¶ããå¿ èŠããªããªã£ãå Žåã¯ãããŒãžã®ã¢ã³ããŒãã¡ãœããã§ã¿ã¹ã¯ã®cancelã¡ãœãããåŒã³åºãã ãã§ãã ãŸãã¯ãéå§ããŒãžããããããããéåžžã¯è©³çŽ°ããŒãžã«ç§»åãããããã®éãè¡ã£ããããããšãã§ããŸãã ãã®å Žåã詳现ããŒãžã«ç§»åãããšéå§ããŒãžã®ã¿ã¹ã¯ãäžæåæ¢ïŒ pause ïŒããæ»ããšãã«åé ïŒ resume ïŒãç¶è¡ã§ããŸãã ãã¢ã«ã€ããŠã¯ãäŸã®ã·ããªãª2ããã³3ãåç §ããŠãã ããã
ã·ããªãª2ã¯ã ææè ããããã£ã®äœ¿çšã瀺ããŠããŸãïŒã³ãŒãã¯éåžžã«æ確ã§ãããããèªåã§ç°¡åã«åŠç¿ã§ããŸãïŒã ææè å±æ§ïŒããŒã¯ã³ïŒã¯ã Scheduler.createOwnerTokenã¡ãœããã䜿çšããŠäœæãããã¿ã¹ã¯ã®ææè ããããã£ãä»ããŠå²ãåœãŠãããŸãïŒããã«ããã以åã®å€ã眮ãæããããŸãïŒã ææè ã®å±æ§ã¯ãåäžã®cancelAllã¡ãœãããæã€ãªããžã§ã¯ãã§ãããã®ã¡ãœããã¯ããããé¢é£ä»ããããŠãããã¹ãŠã®ã¿ã¹ã¯ã«å¯ŸããŠcancelã¡ãœãããåŒã³åºããŸããããã以å€ã¯äœãããŸããã ããã¯åçŽãªã¡ã«ããºã ã§ãå®éã«ã¯ã¿ã¹ã¯ã®é åããµããŒãããã ãã§ãããé¢é£ããã¿ã¹ã¯ãã°ã«ãŒãåãã1åã®åŒã³åºãã§ãã£ã³ã»ã«ããããšãã§ããŸãã ãããã£ãŠãç¬èªã®ãªã¹ããç¶æãããã®ã¢ã¯ã·ã§ã³ã®ããã«ãªã¹ãã確èªããå¿ èŠã¯ãããŸããã ïŒäžæåæ¢ããŠç¶è¡ãããšããåæ§ã®æ±ºå®ãè¡ãããã«ãã³ãŒãå ã§ãã®ãã¿ãŒã³ãç¹°ãè¿ãããšãã§ããŸããïŒ
ãã1ã€ã®éèŠãªã¹ã±ãžã¥ãŒã©æ©èœã¯ã requestDrainã¡ãœããã§ãã ããã«ãããUIã¹ã¬ããã«å¶åŸ¡ã移ãåã«ããã®åªå 床以äžã®ãã¹ãŠã®ã¹ã±ãžã¥ãŒã«ãããã¿ã¹ã¯ãå®äºããããšã確èªã§ããŸãã ããã¯éåžžãã¬ã³ããªã³ã°ã®éå§åã«ãã¹ãŠã®åªå 床ã®é«ãã¿ã¹ã¯ãå®äºããããã«ããããã«äœ¿çšãããŸãã requestDrainã¯ããã¹ãŠã®ã¿ã¹ã¯ããã¯ãªã¢ãããããšãã«å®è£ ãããä¿çäžã®çµæïŒçŽæïŒãè¿ããŸã ã ãã®æç¹ã§ãåªå 床ã®äœãã¿ã¹ã¯ã«é²ãããæ°ããã¿ã¹ã¯ãè¿œå ã§ããŸãã
ç°¡åãªãã¢ã³ã¹ãã¬ãŒã·ã§ã³ã¯ãäŸã®ã·ããªãª5ã«ãããŸãã ç°ãªãã¿ã¹ã¯ã®åãã»ãããèšç»ããé«ãåªå 床ãŸãã¯åªå 床belowNormal㧠requestDrainãåŒã³åºã2ã€ã®ãã¿ã³ããããŸãã é 延çµæãå®è¡ããããšã察å¿ããã¡ãã»ãŒãžã衚瀺ãããŸãïŒjs / drainingscenario.jsïŒïŒ
S.requestDrain(priority).done(function () { window.output("Done draining"); });
以äžã«ç€ºãããã«ã2ã€ã®åºåã䞊åã«æ¯èŒãããšïŒå·ŠåŽãé«ã ãå³åŽãæšæºä»¥äžïŒãåªå é äœã«å¿ããŠé 延çµæãç°ãªãæéã«è¡šç€ºãããããšãããããŸãã
Draining scheduler to high priority | Draining scheduler to belowNormal priority Running job2 at high priority | Running job2 at high priority Done draining | Running job1 at normal priority Running job1 at normal priority | Running job5 at normal priority Running job5 at normal priority | Running job4 at belowNormal priority Running job4 at belowNormal priority | Done draining Running job3 at idle priority | Running job3 at idle priority
ã¹ã±ãžã¥ãŒã©ã§å®çŸ©ãããŠãããã1ã€ã®ã¡ãœããã¯ãçŸåšã®ã¿ã¹ã¯ãŸãã¯ã¯ãªãŒã³ã¢ãããªã¯ãšã¹ãã®èª¬æãè¿ã蚺æããŒã«ã§ããretrieveStateã§ãã ã·ããªãª5ã§requestDrainã®çŽåŸã«åŒã³åºããè¿œå ãããšã次ã®çµæãåŸãããŸãã
id: 28, priority: high id: 27, priority: normal id: 31, priority: normal id: 30, priority: belowNormal id: 29, priority: idle n requests: *priority: high, name: Drain Request 0
延æçµæã®ãã§ãŒã³ã«ãããåªå é äœä»ã
以äžã«èª¬æããããã«ãåã¹ãããã§çµæãåŠçãããé 次å®è¡ããããŒã¿ãèŠæ±ããéåæã¡ãœããã®ã»ããããããšæ³åããŠãã ããã
getCriticalDataAsync().then(function (results1) { var secondaryPages = processCriticalData(results1); return getSecondaryDataAsync(secondaryPages); }).then(function (results2) { var itemsToCache = processSecondaryData(results2); return getBackgroundCacheDataAsync(itemsToCache); }).done(function (results3) { populateCache(results3); });
ããã©ã«ãã§ã¯ããã®ã³ãŒãã¯ãã¹ãŠãUIã¹ã¬ããã§çºçããä»ã®ãã¹ãŠã®èæ¯ã«å¯ŸããŠçŸåšã®åªå 床ã§å®è¡ãããŸãã ãã ããããããprocessCriticalDataé¢æ°ãé«ãåªå 床ã§å®è¡ãã processSecondaryDataã éåžžã¢ãŒãã§åäœããã populateCacheãidleã§åäœããããã§ãããã ã¹ã±ãžã¥ãŒã©ãŒãçŽæ¥æäœããã«ã¯ããã¹ãŠãé£ããæ¹æ³ã§è¡ãå¿ èŠããããŸãã
var S = WinJS.Utilities.Scheduler; getCriticalDataAsync().done(function (results1) { S.schedule(function () { var secondaryPages = processCriticalData(results1); S.schedule(function () { getSecondaryDataAsync(secondaryPages).done(function (results2) { var itemsToCache = processSecondaryData(results2); S.schedule(function () { getBackgroundCacheDataAsync(itemsToCache).done(function (results3) { populateCache(results3); }); }, S.Priority.idle); }); }, S.Priority.normal); }, S.Priority.high); });
ç§ãã¡ã®æèŠã§ã¯ãæ¯å»è ã«è¡ãããšã¯ããã®ãããªã³ãŒããæžãããã楜ããã§ãïŒ ç°¡åã«ããããã«ãæ°ããåªå 床ãèšå®ããããã»ã¹ãå¥ã®ä¿çäžã®çµæã«ã©ããããããããã§ãŒã³ã«æ¿å ¥ã§ããŸãã ãããè¡ãæé©ãªæ¹æ³ã¯ãå®äºããã€ãã³ãã®ãã³ãã©ãŒãåçã«çæããããšã§ããããã«ããããã§ãŒã³ã®åã®ã¹ãããã®çµæãååŸãããç®çã®åªå 床ã§å®è¡ãã¹ã±ãžã¥ãŒã«ãããåãçµæã®Promiseãªããžã§ã¯ããè¿ãããŸã
function schedulePromise(priority) { // â . return function completedHandler (results) { // , // , ... return new WinJS.Promise(function initializer (completeDispatcher) { // . WinJS.Utilities.Scheduler.schedule(function () { completeDispatcher(results); }, priority); }); } }
幞ããªããšã«ããã®ã³ãŒããèªåã§äœæããå¿ èŠã¯ãããŸããã WinJS.Utilities.Schedulerã«ã¯ãäžèšã®ãããª5ã€ã®æ¢è£œã®å®äºãã³ãã©ãŒãæ¢ã«å«ãŸããŠããŸãã ãããã®ãã³ãã©ãŒã¯ããšã©ãŒãçºçãããšãã«ã¿ã¹ã¯ãèªåçã«ãã£ã³ã»ã«ããŸãã ãããã¯ããããã schedulePromiseHigh ã schedulePromiseAboveNormal ã schedulePromiseNormal ã schedulePromiseBelowNormalããã³schedulePromiseIdleãšåŒã°ããŸãã
æ¢è£œã®å®äºãã³ãã©ãŒã䜿çšãããšã次ã®ããã«ãåªå é äœãå€æŽããä¿çäžã®çµæã®ãã§ãŒã³ã«æ£ããã¡ãœããåãæ¿å ¥ããã ãã§ãã
var S = WinJS.Utilities.Scheduler; getCriticalDataAsync().then(S.schedulePromiseHigh).then(function (results1) { var secondaryPages = processCriticalData(results1); return getSecondaryDataAsync(secondaryPages); }).then(S.schedulePromise.normal).then(function (results2) { var itemsToCache = processSecondaryData(results2); return getBackgroundCacheDataAsync(itemsToCache); }).then(S.schedulePromiseIdle).done(function (results3) { populateCache(results3); });
æ確ã«ããããã«ããããã®é¢æ°ã®äœ¿çšã¯ãä¿çäžã®åŒã³åºãã®ãã§ãŒã³ã«ååãæ¿å ¥ããããšã ãã§ãã ããããåå¥ã®é¢æ°ãšããŠçŽæ¥åŒã³åºãå¿ èŠã¯ãããŸããïŒããã¯çŸåšã®ããã¥ã¡ã³ãã§æ確ã«è¿°ã¹ãããŠããªãå ŽåããããŸãïŒã
é·æã«ãããã¿ã¹ã¯
çŸæç¹ã§ç¢ºèªããäœæ¥ã®äŸã¯ãã¹ãŠãç¹å®ã®åªå é äœã§äœæ¥æ©èœãèšç»ããåŒã³åºãæã«ãã®äœæ¥ãè¡ããšããæå³ã§çåœã§ãã ãã ããäžéšã®ã¿ã¹ã¯ã¯å®äºãããŸã§ã«ããªãæéããããå ŽåããããŸãã ãã®å ŽåãUIã¹ã¬ããã§åªå 床ã®é«ãäœæ¥ããããã¯ããããšã¯ã»ãšãã©ãããŸããã
ãã®ãããªç¶æ³ãæ¯æŽããããã«ãã¹ã±ãžã¥ãŒã©ãŒã«ã¯ã æšæºä»¥äžã®åªå 床ã§èšç»ãããã¿ã¹ã¯ã䞊ã¹æ¿ããããã®çµã¿èŸŒã¿ã®ã€ã³ã¿ãŒãã«ã¿ã€ããŒããããã¿ã¹ã¯ããå調çã«ãæ··éããŠæ¬¡ã®äœæ¥ãããã¯ã®ã¹ã±ãžã¥ãŒã«ãå€æŽããå¿ èŠããããã©ããã確èªã§ããŸãã ããã§ã¯ããååçã«ããšããèšèãæ確ã«ããå¿ èŠããããŸããã¿ã¹ã¯ã®å®è¡ã延æããããã®ã¯äœããããŸãããããã¹ãŠãã¢ããªã±ãŒã·ã§ã³ã®UIã®ããã©ãŒãã³ã¹ãããã³ã¢ããªã±ãŒã·ã§ã³å šäœã®ããã©ãŒãã³ã¹ã«åœ±é¿ããããããã®ãããªç¶æ³ãé©åã«åŠçããªããšãèªåèªèº«ã«å®³ãåãŒããŸãïŒ
ãã®ãããªæäœã®å®è£ ã¡ã«ããºã ã¯ãä»äºé¢æ°èªäœãžã®åŒæ°ãšããŠæž¡ãããjobInfoãªããžã§ã¯ããéããŠå®è£ ãããŸãã ãŸããã¹ã³ãŒãå ã®é¢æ°ã§å©çšå¯èœãªãã®ãèŠãŠã¿ãŸããããããã¯ãåºæ¬ã³ãŒãå ã®ããã€ãã®ã³ã¡ã³ãããç解ããã®ãæãç°¡åã§ãã
var job = WinJS.Utilities.Scheduler.schedule(function worker(jobInfo) { //jobInfo.job â , . //Scheduler.currentPriority â . //this â , . }, S.Priority.idle, this);
jobInfoãªããžã§ã¯ãã®ã¡ã³ããŒã¯ã Scheduler.IJobInfoã€ã³ã¿ãŒãã§ãŒã¹ã§å®çŸ©ãããŸãã
ããããã£
- job-ïŒèªã¿åãå°çšïŒ scheduleããè¿ãããã®ãšåããªããžã§ã¯ãã
- shouldYield-ïŒèªã¿åãå°çšïŒããŒã«å€ãã©ã°ãéåžžãã¿ã¹ã¯ãæåã«å®è¡ããããšãã«falseã«èšå®ãããé¢æ°ãUIã¹ã¬ãããã匷å¶çã«å€ããŠãã®äœæ¥ãåã¹ã±ãžã¥ãŒã«ããå¿ èŠãããå Žåã¯trueã«å€æŽãããŸãã
æ¹æ³
- setWorkã¯ãã¿ã¹ã¯ãåã¹ã±ãžã¥ãŒã«ããããã®é¢æ°ã§ãã
- setPromiseã¯é 延çµæã§ãããã¹ã±ãžã¥ãŒã©ã¯ã¿ã¹ã¯ãåã¹ã±ãžã¥ãŒã«ããããŸã§åŸ æ©ããŸããåã¹ã±ãžã¥ãŒã«ã®é¢æ°ã¯é 延çµæã®å€ã§ãã
HTMLã¹ã±ãžã¥ãŒã©ã®äŸã®ã·ããªãª4ã¯ãããã䜿çšããæ¹æ³ã瀺ããŠããŸãã ãYielding Taskãå®è¡ããã¿ã³ãã¯ãªãã¯ãããšã ã¢ã€ãã«åªå 床ã®ã¯ãŒã«ãŒãšåŒã°ããé¢æ°ãã¹ã±ãžã¥ãŒã©ã«è¿œå ããããComplete Yielding Taskããã¿ã³ãã¯ãªãã¯ãããŸã§åçŽã«ã¢ã€ãã«ãµã€ã¯ã«ãå®è¡ãã taskCompletedãtrue ïŒjs /yieldingscenario.jsã2ç§ééã§ã200ããªç§ã«çœ®ãæããããŸãïŒïŒ
S.schedule(function worker(jobInfo) { while (!taskCompleted) { if (jobInfo.shouldYield) { // , window.output("Yielding and putting idle job back on scheduler."); jobInfo.setWork(worker); break; } else { window.output("Running idle yielding job..."); var start = performance.now(); while (performance.now() < (start + 200)) { // ; } } } if (taskCompleted) { window.output("Completed yielding task."); taskCompleted = false; } }, S.Priority.idle);
ã¿ã¹ã¯ãã¢ã¯ãã£ããªå Žåã200msã®éãäœæ¥ããè¡ãã shouldYieldããããã£ãtrueã« èšå®ãããŠãããã©ããã確èªããŸã ã ãã®å Žåãé¢æ°ã¯setWorkã¡ãœãããåŒã³åºããŠèªåèªèº«ïŒãŸãã¯å¿ èŠã«å¿ããŠå¥ã®é¢æ°ïŒãåã¹ã±ãžã¥ãŒã«ããŸãã ãã®ãããªé·ç§»ã¯ãäŸã®ãåªå 床ã®é«ãã¿ã¹ã¯ããã¥ãŒã«è¿œå ããã¿ã³ãã¯ãªãã¯ããããšã§ãé·ãã¿ã¹ã¯ãåäœããŠããéã«èªçºã§ããŸãã ãããã®ã¿ã¹ã¯ïŒåªå 床ãé«ãïŒã次ã®äœæ¥é¢æ°ã®åŒã³åºããŸã§ã©ã®ããã«æ©èœããããããããŸãã ããã«ãã€ã³ã¿ãŒãã§ã€ã¹ã®ä»»æã®å Žæãã¯ãªãã¯ããŠããã®ã¢ã€ãã«ã¿ã¹ã¯ãUIã¹ããªãŒã ããããã¯ããªãããã«ããããšãã§ããŸãã
å¿ èŠã«å¿ããŠãããã«ãããã¢ãŠãããããã«ãäœæ¥é¢æ°ãæåã«éäŒããå¿ èŠãããããšã«æ³šæããŠãã ãã ãã ããæåã«å°ãäœæ¥ãè¡ã£ãŠãããã§ãã¯ãè¡ãã®ã¯æ£åžžã§ãã ç¹°ãè¿ããŸãããããã¯ããªãèªèº«ã®ã³ãŒãå ã§ã®ååã®åé¡ãªã®ã§ãããªãã®ããã¯ã¯ããªãèªèº«ã®è¯å¿ã«ãããŸãã
setPromiseã«é¢ããŠã¯ ãããã¯ãã埮åŠãªã¢ã€ãã¢ã§ãã ã¹ã±ãžã¥ãŒã©ãŒã«å¯ŸããŠsetPromiseãåŒã³åºããŠãã¿ã¹ã¯ãåã¹ã±ãžã¥ãŒã«ããåã«é 延çµæã衚瀺ããããŸã§åŸ æ©ããŸãã ããã«ãã¿ã¹ã¯ã®æ¬¡ã®äœæ¥é¢æ°ã¯ãé 延çµæã®å€ãä»ããŠçŽæ¥æäŸãããŸãã ïŒãã®ããã IJobInfo.setPromiseã¡ãœãã㯠ãWinJSå ã®ä»ã®setPromiseã¡ãœãããè¡ãããã«éåææäœã管çããŸãããããã¯ãWinRTã®é 延ã¡ã«ããºã ã«é¢é£ä»ããããŠããŸããã©ã³ãã ãªéåæAPIããã®é 延çµæã§IJobInfo.setPromiseãåŒã³åºããå Žåãã¹ã±ãžã¥ãŒã©ãŒã¯ããã®æäœã®å®è¡å€ã䜿çšããããšããŸãâããã¯ãäœã§ããäœã§ãå¯èœã§ãâé¢æ°ãšããŠãäŸå€ã«ã€ãªããå¯èœæ§ããããŸãã
äžè¬çã«ã setWorkãããã®äœæ¥é¢æ°ã§ããã§åã¹ã±ãžã¥ãŒã«ãè¡ããããšèšã£ãå Žåã setPromiseã¯ãåã¹ã±ãžã¥ãŒãªã³ã°ãå°ãåŸ ã£ãŠãåŸã§å¿ èŠãªé¢æ°ãæäŸãããŸã§åŸ ã¡ãŸãããšèšããŸãã ããã¯éåžžããã®ãã¥ãŒãåŠçããããã®ã¿ã¹ã¯ã䌎ãå€ãã®ãžã§ãã§æ§æãããäœæ¥ãã¥ãŒãäœæããã®ã«äŸ¿å©ã§ãã 説æã®ããã«ã次ã®ã³ãŒãããããšæ³åããŠãã ããã
var workQueue = []; function addToQueue(worker) { workQueue.push(worker); } S.schedule(function processQueue(jobInfo) { while (work.length) { if (jobInfo.shouldYield) { jobInfo.setWork(processQueue); return; } work.shift()(); // FIFO- . } }}, S.Priority.belowNormal);
æåã®ã¹ã±ãžã¥ãŒã©ãŒåŒã³åºãã®æç¹ã§ãã¥ãŒã«äœããã®äœæ¥ããããšä»®å®ãããšã processQueueã¿ã¹ã¯ã¯ãã®ãã¥ãŒããååçã«ã解æŸããŸãã ãŸããå®è¡æã«æ°ãããžã§ãããã¥ãŒã«è¿œå ããããšã processQueueã¯ããã«å®è¡ãããããã«åã¹ã±ãžã¥ãŒã«ãããŸãã
ãã ããåé¡ã¯ããã¥ãŒã空ã«ãªããšprocessQueueé¢æ°ãçµäºããããšã§ããã€ãŸãããã¥ãŒã«è¿œå ãããžã§ãã¯åŠçãããŸããã ãããä¿®æ£ããã«ã¯ããã¥ãŒã空ã®å Žåã§ãã processQueueãå®æçã«setWorkãç¹°ãè¿ãåŒã³åºãããã«åŒ·å¶ã§ããŸãããããã¯ãªãœãŒã¹ã®æµªè²»ã«ãªããŸãã 代ããã«ã setPromiseãèšå®ããŠããã¥ãŒã«æ°ãããžã§ãã衚瀺ããããŸã§ã¹ã±ãžã¥ãŒã©ãåŸ æ©ãããããšãã§ããŸãã ä»çµã¿ã¯æ¬¡ã®ãšããã§ãã
var workQueue = []; var haveWork = function () { }; // function addToQueue(worker) { workQueue.push(worker); haveWork(); } S.schedule(function processQueue(jobInfo) { while (work.length) { if (jobInfo.shouldYield) { jobInfo.setWork(processQueue); return; } work.shift()(); // FIFO- . } // , , . // , setWork - , , // , addToQueue , , // haveWork , . jobInfo.setPromise(new WinJS.Promise(function (completeDispatcher) { haveWork = function () { completeDispatcher(processQueue) }; })) });
ãã®ã³ãŒãã®ãã¬ãŒã ã¯ãŒã¯å ã§ã workQueueã«ããã€ãã®äœæ¥ãå ¥ããŠããã ã¹ã±ãžã¥ãŒã«åŒã³åºããè¡ããšããŸãã ãã®æç¹ã§ãããã«ããã¥ãŒã空ã«ãªããŸã§ã processQueueé¢æ°ã®whileã«ãŒãã®å åŽã«ããŸã ã 空ã®haveWorké¢æ°ã®åŒã³åºãã«ã¯ãè¿œå ã®æäœã¯ã»ãšãã©å¿ èŠãããŸããã
ãã¥ãŒã空ã«ãªã£ããã whileã«ãŒããçµäºããŸããã processQueueã¯çµäºããŸããã 代ããã«ãæ°ãããžã§ãããã¥ãŒã«è¿œå ããããŸã§åŸ æ©ããããã¹ã±ãžã¥ãŒã©ãŒã«äŒããããšæããŸãã ãã®ããã haveWorké¢æ°ã®ã¹ã¿ãããããŸãããã®ã¹ã¿ãã¯ã processQueueã®é 延çµæãå®äºããå¥ã®é¢æ°ã«çœ®ãæããŠãäœæ¥é¢æ°èªäœã®åã¹ã±ãžã¥ãŒã«ãè¡ãããšãã§ããŸãã
åãç®æšãéæããå¥ã®æ¹æ³ã¯ã次ã®haveWorké¢æ°ã®å²ãåœãŠã䜿çšããããšã§ãã
haveWork = completeDispatcher.bind(null, processQueue);
ããã«ãããå¿åé¢æ°ãšåãçµæãåŸãããŸãããã¯ããŒãžã£ãŒã¯äœæãããŸããã
ãããã«
WinJS ã¹ã±ãžã¥ãŒã© APIã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ã¯ãåäžã®é 延çµæãã§ãŒã³å ã®ããŸããŸãªã¿ã¹ã¯ãå«ããçžå¯Ÿçãªåªå é äœã§UIã¹ã¬ããå ã®ããŸããŸãªã¿ã¹ã¯ãã¹ã±ãžã¥ãŒã«ã§ããŸãã ãã®å Žåãã¢ããªã±ãŒã·ã§ã³ã¯ãã¿ã¹ã¯ãWinJSãåãã¢ããªã±ãŒã·ã§ã³ã«å¯ŸããŠå®è¡ããã¿ã¹ã¯ãšèªåçã«èª¿æŽããŸããããšãã°ãããŒã¿ãã€ã³ãã£ã³ã°ãšã¬ã³ããªã³ã°ã³ã³ãããŒã«ãæé©åããŸãã 䜿çšå¯èœãªåªå é äœãæ éã«äœ¿çšãããšãã¢ããªã±ãŒã·ã§ã³ã¯å šäœçãªããã©ãŒãã³ã¹ãšãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã®åäžã«åããŠéèŠãªæé ãå®è¡ã§ããŸãã
-ã¯ã¬ã€ã°ã»ãããã¯ã·ã¥ããã
ããã°ã©ã ãããŒãžã£ãŒãWindowsãšã³ã·ã¹ãã ããã³ãã¬ãŒã ã¯ãŒã¯ããŒã
æçš¿è ïŒã HTMLãCSSãããã³JavaScriptã䜿çšããWindowsã¹ãã¢ã¢ããªã®ããã°ã©ãã³ã° ãã第2ç
åç §è³æ
ã¹ã±ãžã¥ãŒã©ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ã
HTMLã¹ã±ãžã¥ãŒã©ãŒã®äŸ
Visual Studio 2013ãããŠã³ããŒããã