• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Though currently I am prefer to use CofferScript than Swift, I have thought that the defer of Swift2 is pretty cool. So I wrote a snippet that accomplishes the feature by using yield as like the manner of co is doing.

ruby>>
defer = (g) ->
deferred = []
go = (i) ->
{value,done} = do i.next
unless done
deferred.push value
go i
exit = ->
do f for f in deferred
process.removeListener 'exit', exit
process.on 'exit', exit
try go do g
catch then do exit

foo = (type) -> defer ->
console.log "#{type} 1"
yield -> console.log "#{type} deferred 1!"
yield -> console.log "#{type} deferred 2!"
console.log "#{type} 2"
if type == "exit" then do process.exit
else throw "throw"
console.log "3"

foo "throw"
foo "exit"

RESULTS

throw 1

throw 2

throw deferred 1!

throw deferred 2!

exit 1

exit 2

exit deferred 1!

exit deferred 2!

<<--

posted by genki genki on Sat 10 Oct 2015 at 00:25 with 1 comment
guest guest 04/08 10:46
I have a question, can you contact me at ja-zu98@m.spheremail.net ? Cheers!
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
https://casino-pinco.clients.site/ https://casino-pinco.clients.site/: Pinco Casino регистрация открыла доступ к крутому ... 04/14 21:54
https://moscowremontnik.ru https://moscowremontnik.ru: Слышал много положительных отзывов о Московском ... 04/14 19:08
https://mellstroy.at https://mellstroy.at: Hi there! This is my first visit to your blog! We ... 04/14 19:03
https://russ-remont.ru/ https://russ-remont.ru/: Очень толковая статья, сохраню себе. 04/14 18:45
https://russ-remont.ru/ https://russ-remont.ru/: Приятно видеть профессиональный подход к делу. 04/14 17:56
https://russ-remont.ru/ https://russ-remont.ru/: Ваши советы сэкономили мне кучу времени. 04/14 17:39
https://russ-remont.ru/ https://russ-remont.ru/: Русский Ремонт — отличный выбор для тех, кто ценит... 04/14 17:26
https://www.remontexpress.ru https://www.remontexpress.ru: Радует, что компания работает официально по догово... 04/14 17:20