如何防止悬挂未交付的承诺?

时间:2015-05-21 19:22:51

标签: concurrency clojure

以下是来自clojure的勇敢和真实的例子:

Sub DoYourJob()

Dim x As Integer
Dim y As Integer
Dim z As Integer

Dim sourceWorksheet As Worksheet
Dim targetWorksheet As Worksheet

Set sourceWorksheet = ThisWorkbook.Worksheets("YourSourceWorksheetName")
Set targetWorksheet = ThisWorkbook.Worksheets("YourTargetWorksheetName")

Dim existing As Boolean
'Let the macro read an create the table

'Creating the rows
For x = 2 To sourceWorksheet.Cells(sourceWorksheet.Rows.Count, 1).End(xlUp).Row
    existing = False
    For y = 2 To targetWorksheet.Cells(targetWorksheet.Rows.Count, 1).End(xlUp).Row
        If targetWorksheet.Cells(y, 1).Value = sourceWorksheet.Cells(x, 1).Value Then
            existing = True
            Exit For
        End If
    Next y
    If Not existing Then
        targetWorksheet.Cells(targetWorksheet.Cells(targetWorksheet.Rows.Count, 1).End(xlUp).Row + 1, 1).Value = sourceWorksheet.Cells(x, 1).Value
    End If
Next x

'Creating the columns
For x = 2 To sourceWorksheet.Cells(sourceWorksheet.Rows.Count, 1).End(xlUp).Row
    existing = False
    For y = 2 To targetWorksheet.Cells(1, targetWorksheet.Columns.Count).End(xlToLeft).Column
        If targetWorksheet.Cells(1, y).Value = sourceWorksheet.Cells(x, 2).Value Then
            existing = True
            Exit For
        End If
    Next y
    If Not existing Then
        targetWorksheet.Cells(1, targetWorksheet.Cells(1, targetWorksheet.Columns.Count).End(xlToLeft).Column + 1).Value = sourceWorksheet.Cells(x, 2).Value
    End If
Next x

'Iterate to fill the table
For z = 1 To sourceWorksheet.Cells(sourceWorksheet.Rows.Count, 1).End(xlUp).Row
    For y = 2 To targetWorksheet.Cells(targetWorksheet.Rows.Count, 1).End(xlUp).Row
        If targetWorksheet.Cells(y, 1).Value = sourceWorksheet.Cells(z, 1).Value Then
            For x = 2 To targetWorksheet.Cells(1, targetWorksheet.Columns.Count).End(xlToLeft).Column
                If targetWorksheet.Cells(1, x).Value = sourceWorksheet.Cells(z, 2).Value Then
                    targetWorksheet.Cells(y, x).Value = sourceWorksheet.Cells(z, 3).Value
                    Exit For
                End If
            Next x
            Exit For
        End If
    Next y
Next z

End Sub

如果没有一种黄油产品符合我们的标准怎么办?

1 个答案:

答案 0 :(得分:3)

(let [butter-promise (promise)]
  ;; ...
  (if-let [winner (deref butter-promise 10000 nil)]
    (println "And the winner is:" winner)
    (println "Butter timed out."))